Skip to content

Commit

Permalink
Improve CJK links support (#57)
Browse files Browse the repository at this point in the history
  • Loading branch information
fregante authored Aug 26, 2024
1 parent 301a6c3 commit 6b702d0
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
8 changes: 7 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,13 @@ function shortenRepoUrl(href, currentUrl = 'https://github.com') {

cleanHref.push(parsedUrl.hash);

return cleanHref.join('');
// The user prefers seeing the URL as it was typed, so we need to decode it
try {
return decodeURI(cleanHref.join(''));
} catch {
// Decoding fails if the URL includes '%%'
return href;
}
}

if (user && !repo) {
Expand Down
4 changes: 4 additions & 0 deletions index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -535,6 +535,10 @@ test('External URLs', urlMatcherMacro, new Map([
'https://example.com/nodejs/node/blob/cc8fc46/.gitignore',
'example.com/nodejs/node/blob/cc8fc46/.gitignore',
],
[
'https://example.site/한글로-된-URL',
'example.site/한글로-된-URL',
],
]));

test('applyToLink', t => {
Expand Down

0 comments on commit 6b702d0

Please sign in to comment.