Skip to content

Commit 55f75aa

Browse files
committed
Drop need for punycode
1 parent c7118d7 commit 55f75aa

File tree

2 files changed

+7
-14
lines changed

2 files changed

+7
-14
lines changed

index.js

+6-12
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import reservedNames from 'github-reserved-names/reserved-names.json' with { type: 'json' };
2-
import punycode from 'punycode.js';
32

43
const patchDiffRegex = /[.](patch|diff)$/;
54
const releaseRegex = /^releases[/]tag[/]([^/]+)/;
@@ -159,12 +158,13 @@ function shortenRepoUrl(href, currentUrl = 'https://github.com') {
159158
* Shorten URL
160159
*/
161160
if (isReserved || pathname === '/' || (!isLocal && !isRaw && !isRedirection)) {
161+
const origin = href.split('/', 3).join('/');
162162
const parsedUrl = new URL(href);
163163
const cleanHref = [
164-
parsedUrl.origin
164+
origin
165165
.replace(/^https:[/][/]/, '')
166166
.replace(/^www[.]/, ''),
167-
parsedUrl.pathname
167+
decodeURI(parsedUrl.pathname)
168168
.replace(/[/]$/, ''),
169169
];
170170

@@ -175,15 +175,9 @@ function shortenRepoUrl(href, currentUrl = 'https://github.com') {
175175
cleanHref.push(parsedUrl.search);
176176
}
177177

178-
cleanHref.push(parsedUrl.hash);
178+
cleanHref.push(decodeURI(parsedUrl.hash));
179179

180-
// The user prefers seeing the URL as it was typed, so we need to decode it
181-
try {
182-
return decodeURI(cleanHref.map(x => punycode.toUnicode(x)).join(''));
183-
} catch {
184-
// Decoding fails if the URL includes '%%'
185-
return href;
186-
}
180+
return cleanHref.join('');
187181
}
188182

189183
if (user && !repo) {
@@ -324,7 +318,7 @@ export function applyToLink(a, currentUrl) {
324318
// And if there are no additional images in the link
325319
&& !a.firstElementChild
326320
) {
327-
const url = getLinkHref(a);
321+
const url = a.textContent;
328322
const shortened = shortenRepoUrl(url, currentUrl);
329323
a.replaceChildren(
330324
...shortened.split(

package.json

+1-2
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,7 @@
4242
}
4343
},
4444
"dependencies": {
45-
"github-reserved-names": "^2.0.5",
46-
"punycode.js": "^2.3.1"
45+
"github-reserved-names": "^2.0.5"
4746
},
4847
"devDependencies": {
4948
"@sindresorhus/tsconfig": "^5.0.0",

0 commit comments

Comments
 (0)