diff --git a/lib/encode_url.ts b/lib/encode_url.ts index b2800748..53242adc 100644 --- a/lib/encode_url.ts +++ b/lib/encode_url.ts @@ -9,6 +9,7 @@ const encodeURL = (str: string) => { if (parsed.origin === 'null') return str; parsed.search = encodeURI(unescape(parsed.search)); + parsed.pathname = encodeURI(decodeURI(parsed.pathname)); // preserve IDN return format(parsed, { unicode: true }); } diff --git a/test/encode_url.spec.ts b/test/encode_url.spec.ts index 583df516..9ebb98f2 100644 --- a/test/encode_url.spec.ts +++ b/test/encode_url.spec.ts @@ -102,4 +102,8 @@ describe('encodeURL', () => { const content = 'data:,Hello%2C%20World!'; encodeURL(content).should.eql(content); }); + it('encode pathname', () => { + const content = 'https://fóo.com/páth%20[square]'; + encodeURL(content).should.eql('https://fóo.com/p%C3%A1th%20%5Bsquare%5D'); + }); });