diff --git a/index.js b/index.js index 4eea255..61016d5 100644 --- a/index.js +++ b/index.js @@ -146,7 +146,9 @@ const normalizeUrl = (urlString, options) => { // Decode URI octets if (urlObj.pathname) { - urlObj.pathname = decodeURI(urlObj.pathname); + try { + urlObj.pathname = decodeURI(urlObj.pathname); + } catch (_) {} } // Remove directory index diff --git a/test.js b/test.js index dba2e13..85e706d 100644 --- a/test.js +++ b/test.js @@ -24,6 +24,7 @@ test('main', t => { t.is(normalizeUrl('https://foo.com/http://bar.com'), 'https://foo.com/http://bar.com'); t.is(normalizeUrl('https://foo.com/http://bar.com/foo//bar'), 'https://foo.com/http://bar.com/foo/bar'); t.is(normalizeUrl('http://sindresorhus.com/%7Efoo/'), 'http://sindresorhus.com/~foo', 'decode URI octets'); + t.is(normalizeUrl('https://foo.com/%FAIL%/07/94/ca/55.jpg'), 'https://foo.com/%FAIL%/07/94/ca/55.jpg'); t.is(normalizeUrl('http://sindresorhus.com/?'), 'http://sindresorhus.com'); t.is(normalizeUrl('êxample.com'), 'http://xn--xample-hva.com'); t.is(normalizeUrl('http://sindresorhus.com/?b=bar&a=foo'), 'http://sindresorhus.com/?a=foo&b=bar');