Skip to content

Commit

Permalink
fix: Git provider endpoint validation
Browse files Browse the repository at this point in the history
Signed-off-by: Oleksii Orel <[email protected]>
  • Loading branch information
olexii4 committed Jul 2, 2024
1 parent 0d31690 commit 84478a8
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,19 @@ describe('GitProviderEndpoint', () => {
expect(screen.queryByText('The URL is not valid.')).toBeFalsy();
});

it('should handle a correct endpoint with the port part', () => {
const endpoint = 'https://bitbucket.org:8443';
renderComponent(undefined);

expect(mockOnChange).not.toHaveBeenCalled();

const input = screen.getByRole('textbox');
userEvent.paste(input, endpoint);

expect(mockOnChange).toHaveBeenCalledWith(expect.stringContaining(endpoint), true);
expect(screen.queryByText('The URL is not valid.')).toBeFalsy();
});

it('should handle endpoint started with an incorrect protocol', () => {
const endpoint = 'asdf://provider/endpoint';
renderComponent(undefined);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,8 @@ export class GitProviderEndpoint extends React.PureComponent<Props, State> {
validated: ValidatedOptions;
sanitized: string;
} {
const validationRe = /^https?:\/\/(?:(?:[a-z\d]+(?:-[a-z\d]+)*)\.)+[a-z]{2,}(?:\/[^\s]*)?$/i;
const validationRe =
/^https?:\/\/(?:(?:[a-z\d]+(?:-[a-z\d]+)*)\.)+[a-z]{2,}(?:\/[^\s]*)?(?::\d+)?$/i;

if (validationRe.test(providerEndpoint) === false) {
return {
Expand Down

0 comments on commit 84478a8

Please sign in to comment.