From c3378ba621860c66938cd78f5b842bfbecf157dd Mon Sep 17 00:00:00 2001 From: Yohann Valentin Date: Wed, 30 Jul 2025 15:59:26 +0200 Subject: [PATCH 1/2] fix: enhance URL parsing logic in isLocalLink method --- apps/nuxt/src/tools/marked.ts | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/apps/nuxt/src/tools/marked.ts b/apps/nuxt/src/tools/marked.ts index b10b9e9d6..8dc40208b 100644 --- a/apps/nuxt/src/tools/marked.ts +++ b/apps/nuxt/src/tools/marked.ts @@ -32,9 +32,14 @@ export class Marked { } public static isLocalLink(token: Tokens.Link): boolean { - if (URL.canParse(token.href)) { + if (!token.href) { + return false + } + + const url = this.getUrl(token) + + if (url) { const config = useRuntimeConfig() - const url = new URL(token.href) return ( [config.public.siteUrl, 'https://preprod.mission-transition-ecologique.incubateur.net', 'http://localhost:4242'].includes( @@ -45,4 +50,19 @@ export class Marked { return token.href.startsWith('/') } + + private static getUrl(token: Tokens.Link) { + let url: URL | undefined + if ('canParse' in URL && URL.canParse(token.href)) { + url = new URL(token.href) + } else { + try { + url = new URL(token.href) + } catch (e) { + url = undefined + } + } + + return url + } } From 6001f09fe0163183bfd6f35cb6f12cf35e8c7f8e Mon Sep 17 00:00:00 2001 From: Yohann Valentin Date: Thu, 31 Jul 2025 11:48:37 +0200 Subject: [PATCH 2/2] fix: refactor URL parsing method for improved error handling --- apps/nuxt/src/tools/marked.ts | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) diff --git a/apps/nuxt/src/tools/marked.ts b/apps/nuxt/src/tools/marked.ts index 8dc40208b..6fa542b06 100644 --- a/apps/nuxt/src/tools/marked.ts +++ b/apps/nuxt/src/tools/marked.ts @@ -36,7 +36,7 @@ export class Marked { return false } - const url = this.getUrl(token) + const url = this._getUrl(token) if (url) { const config = useRuntimeConfig() @@ -51,18 +51,11 @@ export class Marked { return token.href.startsWith('/') } - private static getUrl(token: Tokens.Link) { - let url: URL | undefined - if ('canParse' in URL && URL.canParse(token.href)) { - url = new URL(token.href) - } else { - try { - url = new URL(token.href) - } catch (e) { - url = undefined - } + private static _getUrl(token: Tokens.Link) { + try { + return new URL(token.href) + } catch (e) { + return undefined } - - return url } }