From 3222e4cf3da9f4cd2be84bf03c53692122d31ed6 Mon Sep 17 00:00:00 2001 From: Abhijeet Prasad Date: Mon, 27 Nov 2023 13:33:33 -0500 Subject: [PATCH 1/2] fix(utils): regex match port to stop accidental replace --- packages/utils/src/url.ts | 4 ++-- packages/utils/test/url.test.ts | 4 ++++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/packages/utils/src/url.ts b/packages/utils/src/url.ts index 71ce23e63a57..eb80f77ae6ab 100644 --- a/packages/utils/src/url.ts +++ b/packages/utils/src/url.ts @@ -70,8 +70,8 @@ export function getSanitizedUrlString(url: PartialURL): string { // Always filter out authority .replace(/^.*@/, '[filtered]:[filtered]@') // Don't show standard :80 (http) and :443 (https) ports to reduce the noise - .replace(':80', '') - .replace(':443', '')) || + .replace(/(:80)$/, '') + .replace(/(:443)$/, '')) || ''; return `${protocol ? `${protocol}://` : ''}${filteredHost}${path}`; diff --git a/packages/utils/test/url.test.ts b/packages/utils/test/url.test.ts index 9caad36f572b..d58f7cf205a8 100644 --- a/packages/utils/test/url.test.ts +++ b/packages/utils/test/url.test.ts @@ -74,6 +74,10 @@ describe('getSanitizedUrlString', () => { ['same-origin url', '/api/v4/users?id=123', '/api/v4/users'], ['url without a protocol', 'example.com', 'example.com'], ['url without a protocol with a path', 'example.com/sub/path?id=123', 'example.com/sub/path'], + ['url with port 8080', 'http://172.31.12.144:8080/test', 'http://172.31.12.144:8080/test'], + ['url with port 4433', 'http://172.31.12.144:4433/test', 'http://172.31.12.144:4433/test'], + ['url with port 443', 'http://172.31.12.144:443/test', 'http://172.31.12.144/test'], + ['url with IP and port 80', 'http://172.31.12.144:80/test', 'http://172.31.12.144/test'], ])('returns a sanitized URL for a %s', (_, rawUrl: string, sanitizedURL: string) => { const urlObject = parseUrl(rawUrl); expect(getSanitizedUrlString(urlObject)).toEqual(sanitizedURL); From d3d70cfccec8618b465ecae5886ccc5787d36c71 Mon Sep 17 00:00:00 2001 From: Abhijeet Prasad Date: Tue, 28 Nov 2023 10:30:56 -0500 Subject: [PATCH 2/2] add comment about adding new URL --- packages/utils/src/url.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/utils/src/url.ts b/packages/utils/src/url.ts index eb80f77ae6ab..d5d773e27389 100644 --- a/packages/utils/src/url.ts +++ b/packages/utils/src/url.ts @@ -70,6 +70,7 @@ export function getSanitizedUrlString(url: PartialURL): string { // Always filter out authority .replace(/^.*@/, '[filtered]:[filtered]@') // Don't show standard :80 (http) and :443 (https) ports to reduce the noise + // TODO: Use new URL global if it exists .replace(/(:80)$/, '') .replace(/(:443)$/, '')) || '';