Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(cdk): support any query string inside URL #9254

Merged
merged 1 commit into from
Sep 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions projects/cdk/utils/miscellaneous/is-valid-url.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
/**
* @deprecated: drop in v5.0
*/
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`(\?[)(;&a-z\d%_.~+=-]*)?` + // 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
Loading