Skip to content

Commit

Permalink
fix(cdk): support any query string inside URL
Browse files Browse the repository at this point in the history
  • Loading branch information
splincode committed Sep 28, 2024
1 parent 8e78f6f commit 67575f5
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
8 changes: 3 additions & 5 deletions projects/cdk/utils/miscellaneous/is-valid-url.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
export function tuiIsValidUrl(url: string): boolean {
const pattern = new RegExp(
return new RegExp(
String.raw`^([a-zA-Z]+:\/\/)?` + // protocol
String.raw`((([a-z\d]([a-z\d-]*[a-z\d])*)\.)+[a-z]{2,}|localhost|` + // domain name
String.raw`((\d{1,3}\.){3}\d{1,3}))` + // OR IP (v4) address
String.raw`(\:\d+)?(\/[-a-z\d%_.~+]*)*` + // port and path
String.raw`(\?[;&a-z\d%_.~+=-]*)?` + // query string
String.raw`(\?.*)?` + // query string
String.raw`(\#[-a-z\d_]*)?$`, // fragment locator
'i',
);

return pattern.test(url);
).test(url);
}
10 changes: 10 additions & 0 deletions projects/cdk/utils/miscellaneous/test/is-valid-url.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,16 @@ describe('tuiIsValidUrl', () => {
expect(tuiIsValidUrl('127.0.0.1:8080')).toBe(true);
expect(tuiIsValidUrl('localhost:3333')).toBe(true);
expect(tuiIsValidUrl('ftp://ftp.example:21/')).toBe(true);

expect(
tuiIsValidUrl(
'https://jira.com/browse/ETC-5972?filter=411557&jql=project%20%3D%ETC%20AND%20component%20in%20(Auth)',
),
).toBe(true);

expect(
tuiIsValidUrl('jira.com/?jql=project%20%3D%ETC%20AND%%20in%20(Auth)'),
).toBe(true);
});

it('invalid', () => {
Expand Down

0 comments on commit 67575f5

Please sign in to comment.