Skip to content

Commit

Permalink
Duplicate slash removal regex restricts protocol to 50 chars
Browse files Browse the repository at this point in the history
  • Loading branch information
gcox committed Jul 30, 2020
1 parent c33db18 commit 49c0dc8
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion index.js
Expand Up @@ -117,7 +117,7 @@ const normalizeUrl = (urlString, options) => {

// Remove duplicate slashes if not preceded by a protocol
if (urlObj.pathname) {
urlObj.pathname = urlObj.pathname.replace(/(?:(?<=[a-z\d]{31,}:)|(?<![a-z\d]{2,}:))\/{2,}/g, '/');
urlObj.pathname = urlObj.pathname.replace(/(?:(?<=[a-z\d]{51,}:)|(?<![a-z\d]{2,}:))\/{2,}/g, '/');
}

// Decode URI octets
Expand Down
4 changes: 2 additions & 2 deletions test.js
Expand Up @@ -212,8 +212,8 @@ test('remove duplicate pathname slashes', t => {
t.is(normalizeUrl('http://sindresorhus.com/git://sindresorhus.com//foo'), 'http://sindresorhus.com/git://sindresorhus.com/foo');
t.is(normalizeUrl('http://sindresorhus.com//foo/git://sindresorhus.com//foo'), 'http://sindresorhus.com/foo/git://sindresorhus.com/foo');
t.is(normalizeUrl('http://sindresorhus.com/a://sindresorhus.com//foo'), 'http://sindresorhus.com/a:/sindresorhus.com/foo');
t.is(normalizeUrl('http://sindresorhus.com/alongprotocolwithin30charlimit://sindresorhus.com//foo'), 'http://sindresorhus.com/alongprotocolwithin30charlimit://sindresorhus.com/foo');
t.is(normalizeUrl('http://sindresorhus.com/alongprotocolexceeds30charlimit://sindresorhus.com//foo'), 'http://sindresorhus.com/alongprotocolexceeds30charlimit:/sindresorhus.com/foo');
t.is(normalizeUrl('http://sindresorhus.com/alongprotocolwithin50charlimitxxxxxxxxxxxxxxxxxxxx://sindresorhus.com//foo'), 'http://sindresorhus.com/alongprotocolwithin50charlimitxxxxxxxxxxxxxxxxxxxx://sindresorhus.com/foo');
t.is(normalizeUrl('http://sindresorhus.com/alongprotocolexceeds50charlimitxxxxxxxxxxxxxxxxxxxxx://sindresorhus.com//foo'), 'http://sindresorhus.com/alongprotocolexceeds50charlimitxxxxxxxxxxxxxxxxxxxxx:/sindresorhus.com/foo');
});

test('data URL', t => {
Expand Down

0 comments on commit 49c0dc8

Please sign in to comment.