Fix RegExpArrayMatch guard

environments/review-docs-renov-k6e5t2/deployments/15595
wvffle 2022-11-17 21:01:11 +00:00 zatwierdzone przez Kasper Seweryn
rodzic 6370f03a23
commit 6b537cb8bb
1 zmienionych plików z 2 dodań i 1 usunięć

Wyświetl plik

@ -9,6 +9,7 @@ showdown.extension('openExternalInNewTab', {
regex: /<a.+?href.+">/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
}