From 6b537cb8bbc99a178d8c4d4ddece21fbacba9d07 Mon Sep 17 00:00:00 2001 From: wvffle Date: Thu, 17 Nov 2022 21:01:11 +0000 Subject: [PATCH] Fix RegExpArrayMatch guard --- front/src/composables/useMarkdown.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/front/src/composables/useMarkdown.ts b/front/src/composables/useMarkdown.ts index b4e05a616..f1ab9e7ab 100644 --- a/front/src/composables/useMarkdown.ts +++ b/front/src/composables/useMarkdown.ts @@ -9,6 +9,7 @@ showdown.extension('openExternalInNewTab', { regex: //g, replace (text: string) { const matches = text.match(/href="(.+)">/) ?? [] + const url = matches[1] ?? './' if ((!url.startsWith('http://') && !url.startsWith('https://')) || url.startsWith('mailto:')) { @@ -16,7 +17,7 @@ showdown.extension('openExternalInNewTab', { } const { hostname } = new URL(url) - return hostname !== location.hostname + return hostname !== location.hostname && typeof matches[0] === 'string' ? text.replace(matches[0], `href="${url}" target="_blank" rel="noopener noreferrer">`) : text }