Skip to content

Commit

Permalink
Don't throw if decoding the path fails (#104)
Browse files Browse the repository at this point in the history
  • Loading branch information
Kikobeats authored Jan 31, 2020
1 parent 063847a commit 062b426
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
4 changes: 3 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down

0 comments on commit 062b426

Please sign in to comment.