Skip to content

Commit

Permalink
fix(editor): Update git repo url validation regex (#7151)
Browse files Browse the repository at this point in the history
  • Loading branch information
cstuncsik authored Sep 11, 2023
1 parent fd800b6 commit e51f173
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 1 deletion.
3 changes: 2 additions & 1 deletion packages/editor-ui/src/views/SettingsSourceControl.vue
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,8 @@ const repoUrlValidationRules: Array<Rule | RuleGroup> = [
{
name: 'MATCH_REGEX',
config: {
regex: /^(?!https?:\/\/)(?:git|ssh|git@[-\w.]+):(\/\/)?(.*?)(\.git)(\/?|\#[-\d\w._]+?)$/,
regex:
/^git@(?:\[[0-9a-fA-F:]+\]|(?:[a-zA-Z0-9-]+\.)*[a-zA-Z0-9-]+)(?::[0-9]+)*:(?:v[0-9]+\/)?[a-zA-Z0-9_.\-\/]+(\.git)?(?:\/[a-zA-Z0-9_.\-\/]+)*$/,
message: locale.baseText('settings.sourceControl.repoUrlInvalid'),
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,4 +128,49 @@ describe('SettingsSourceControl', () => {
expect(queryByTestId('source-control-connected-content')).not.toBeInTheDocument(),
);
}, 10000);

describe('should test repo URLs', () => {
beforeEach(() => {
settingsStore.settings.enterprise[EnterpriseEditionFeature.SourceControl] = true;
});

test.each([
['git@github.com:user/repository.git', true],
['git@github.enterprise.com:org-name/repo-name.git', true],
['git@192.168.1.101:2222:user/repo.git', true],
['git@github.com:user/repo.git/path/to/subdir', true],
// The opening bracket in curly braces makes sure it is not treated as a special character by the 'user-event' library
['git@{[}2001:db8:100:f101:210:a4ff:fee3:9566]:user/repo.git', true],
['git@github.com:org/suborg/repo.git', true],
['git@github.com:user-name/repo-name.git', true],
['git@github.com:user_name/repo_name.git', true],
['git@github.com:user/repository', true],
['git@github.enterprise.com:org-name/repo-name', true],
['git@192.168.1.101:2222:user/repo', true],
['git@ssh.dev.azure.com:v3/User/repo/directory', true],
['http://github.com/user/repository', false],
['https://github.com/user/repository', false],
])('%s', async (url: string, isValid: boolean) => {
await nextTick();
const { container, queryByText } = renderComponent({
pinia,
});

await waitFor(() => expect(sourceControlStore.preferences.publicKey).not.toEqual(''));

const repoUrlInput = container.querySelector('input[name="repoUrl"]')!;

await userEvent.click(repoUrlInput);
await userEvent.type(repoUrlInput, url);
await userEvent.tab();

const inputError = expect(queryByText('The Git repository URL is not valid'));

if (isValid) {
inputError.not.toBeInTheDocument();
} else {
inputError.toBeInTheDocument();
}
});
});
});

0 comments on commit e51f173

Please sign in to comment.