Skip to content

Commit 09b0ad4

Browse files
authored
fix: enhance URL parsing logic in isLocalLink method (canParse) (#2121)
1 parent dd0ed9e commit 09b0ad4

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

apps/nuxt/src/tools/marked.ts

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,14 @@ export class Marked {
3232
}
3333

3434
public static isLocalLink(token: Tokens.Link): boolean {
35-
if (URL.canParse(token.href)) {
35+
if (!token.href) {
36+
return false
37+
}
38+
39+
const url = this._getUrl(token)
40+
41+
if (url) {
3642
const config = useRuntimeConfig()
37-
const url = new URL(token.href)
3843

3944
return (
4045
[config.public.siteUrl, 'https://preprod.mission-transition-ecologique.incubateur.net', 'http://localhost:4242'].includes(
@@ -45,4 +50,12 @@ export class Marked {
4550

4651
return token.href.startsWith('/')
4752
}
53+
54+
private static _getUrl(token: Tokens.Link) {
55+
try {
56+
return new URL(token.href)
57+
} catch (e) {
58+
return undefined
59+
}
60+
}
4861
}

0 commit comments

Comments
 (0)