Skip to content

Commit dd34361

Browse files
authored
fix(utils): regex match port to stop accidental replace (#9676)
1 parent bbe8812 commit dd34361

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

packages/utils/src/url.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,9 @@ export function getSanitizedUrlString(url: PartialURL): string {
7070
// Always filter out authority
7171
.replace(/^.*@/, '[filtered]:[filtered]@')
7272
// Don't show standard :80 (http) and :443 (https) ports to reduce the noise
73-
.replace(':80', '')
74-
.replace(':443', '')) ||
73+
// TODO: Use new URL global if it exists
74+
.replace(/(:80)$/, '')
75+
.replace(/(:443)$/, '')) ||
7576
'';
7677

7778
return `${protocol ? `${protocol}://` : ''}${filteredHost}${path}`;

packages/utils/test/url.test.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,10 @@ describe('getSanitizedUrlString', () => {
7474
['same-origin url', '/api/v4/users?id=123', '/api/v4/users'],
7575
['url without a protocol', 'example.com', 'example.com'],
7676
['url without a protocol with a path', 'example.com/sub/path?id=123', 'example.com/sub/path'],
77+
['url with port 8080', 'http://172.31.12.144:8080/test', 'http://172.31.12.144:8080/test'],
78+
['url with port 4433', 'http://172.31.12.144:4433/test', 'http://172.31.12.144:4433/test'],
79+
['url with port 443', 'http://172.31.12.144:443/test', 'http://172.31.12.144/test'],
80+
['url with IP and port 80', 'http://172.31.12.144:80/test', 'http://172.31.12.144/test'],
7781
])('returns a sanitized URL for a %s', (_, rawUrl: string, sanitizedURL: string) => {
7882
const urlObject = parseUrl(rawUrl);
7983
expect(getSanitizedUrlString(urlObject)).toEqual(sanitizedURL);

0 commit comments

Comments
 (0)