From 4ee3d74764fcf36e83e737d6dde8cb31daa9d365 Mon Sep 17 00:00:00 2001 From: splincode Date: Sat, 28 Sep 2024 17:43:08 +0300 Subject: [PATCH] fix(cdk): support any query string inside URL --- projects/cdk/utils/miscellaneous/is-valid-url.ts | 11 ++++++----- .../cdk/utils/miscellaneous/test/is-valid-url.spec.ts | 10 ++++++++++ 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/projects/cdk/utils/miscellaneous/is-valid-url.ts b/projects/cdk/utils/miscellaneous/is-valid-url.ts index ae0283ac68a6..5f0f5fb2f9d1 100644 --- a/projects/cdk/utils/miscellaneous/is-valid-url.ts +++ b/projects/cdk/utils/miscellaneous/is-valid-url.ts @@ -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`(\?.*)?` + // query string String.raw`(\#[-a-z\d_]*)?$`, // fragment locator 'i', - ); - - return pattern.test(url); + ).test(url); } diff --git a/projects/cdk/utils/miscellaneous/test/is-valid-url.spec.ts b/projects/cdk/utils/miscellaneous/test/is-valid-url.spec.ts index 7792dc38b95c..698d9eec0cae 100644 --- a/projects/cdk/utils/miscellaneous/test/is-valid-url.spec.ts +++ b/projects/cdk/utils/miscellaneous/test/is-valid-url.spec.ts @@ -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', () => {