From 4ba08ec1e6d5758ff6f506bcfa959fdecc2c23dd Mon Sep 17 00:00:00 2001 From: Joel Marcotte Date: Tue, 4 Dec 2018 16:53:48 -0500 Subject: [PATCH 1/3] Failing test --- test.js | 1 + 1 file changed, 1 insertion(+) diff --git a/test.js b/test.js index 9333d35..9eae368 100644 --- a/test.js +++ b/test.js @@ -31,6 +31,7 @@ test('main', t => { t.is(normalizeUrl('http://sindresorhus.com////foo/bar'), 'http://sindresorhus.com/foo/bar'); t.is(normalizeUrl('http://sindresorhus.com////foo////bar'), 'http://sindresorhus.com/foo/bar'); t.is(normalizeUrl('//sindresorhus.com/', {normalizeProtocol: false}), '//sindresorhus.com'); + t.is(normalizeUrl('//sindresorhus.com//foo', {normalizeProtocol: false}), '//sindresorhus.com/foo'); t.is(normalizeUrl('//sindresorhus.com:80/', {normalizeProtocol: false}), '//sindresorhus.com'); t.is(normalizeUrl('http://sindresorhus.com/foo#bar'), 'http://sindresorhus.com/foo#bar'); t.is(normalizeUrl('http://sindresorhus.com/foo#bar', {stripHash: true}), 'http://sindresorhus.com/foo'); From 7f9f1c540f3cb45f1d31ce0af33d32ed0f7efd44 Mon Sep 17 00:00:00 2001 From: Joel Marcotte Date: Tue, 4 Dec 2018 16:59:25 -0500 Subject: [PATCH 2/3] Fix for double-slash --- index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.js b/index.js index 7e9e294..da03db0 100644 --- a/index.js +++ b/index.js @@ -74,7 +74,7 @@ module.exports = (urlString, options) => { if (urlObj.pathname) { // TODO: Use the following instead when targeting Node.js 10 // `urlObj.pathname = urlObj.pathname.replace(/(? { + urlObj.pathname = urlObj.pathname.replace(/((?!:).|^)\/{2,}/g, (_, p1) => { if (/^(?!\/)/g.test(p1)) { return `${p1}/`; } From 94c650d1ce9d824155543b9fa4c84f105983080a Mon Sep 17 00:00:00 2001 From: Joel Marcotte Date: Tue, 4 Dec 2018 17:02:30 -0500 Subject: [PATCH 3/3] Add RyanBard's tests --- test.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/test.js b/test.js index 9eae368..cb14874 100644 --- a/test.js +++ b/test.js @@ -32,6 +32,10 @@ test('main', t => { t.is(normalizeUrl('http://sindresorhus.com////foo////bar'), 'http://sindresorhus.com/foo/bar'); t.is(normalizeUrl('//sindresorhus.com/', {normalizeProtocol: false}), '//sindresorhus.com'); t.is(normalizeUrl('//sindresorhus.com//foo', {normalizeProtocol: false}), '//sindresorhus.com/foo'); + t.is(normalizeUrl('http://sindresorhus.com:5000///foo'), 'http://sindresorhus.com:5000/foo'); + t.is(normalizeUrl('http://sindresorhus.com///foo'), 'http://sindresorhus.com/foo'); + t.is(normalizeUrl('http://sindresorhus.com:5000//foo'), 'http://sindresorhus.com:5000/foo'); + t.is(normalizeUrl('http://sindresorhus.com//foo'), 'http://sindresorhus.com/foo'); t.is(normalizeUrl('//sindresorhus.com:80/', {normalizeProtocol: false}), '//sindresorhus.com'); t.is(normalizeUrl('http://sindresorhus.com/foo#bar'), 'http://sindresorhus.com/foo#bar'); t.is(normalizeUrl('http://sindresorhus.com/foo#bar', {stripHash: true}), 'http://sindresorhus.com/foo');