Skip to content

Commit

Permalink
feat(encodeUrl): encode pathname (hexojs#388)
Browse files Browse the repository at this point in the history
  • Loading branch information
uiolee authored and dimaslanjaka committed Oct 3, 2024
1 parent 38241ca commit 6f86e39
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/encode_url.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 });
}
Expand Down
4 changes: 4 additions & 0 deletions test/encode_url.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
});
});

0 comments on commit 6f86e39

Please sign in to comment.