kopia lustrzana https://dev.funkwhale.audio/funkwhale/funkwhale
Fix RegExpArrayMatch guard
rodzic
6370f03a23
commit
6b537cb8bb
|
@ -9,6 +9,7 @@ showdown.extension('openExternalInNewTab', {
|
||||||
regex: /<a.+?href.+">/g,
|
regex: /<a.+?href.+">/g,
|
||||||
replace (text: string) {
|
replace (text: string) {
|
||||||
const matches = text.match(/href="(.+)">/) ?? []
|
const matches = text.match(/href="(.+)">/) ?? []
|
||||||
|
|
||||||
const url = matches[1] ?? './'
|
const url = matches[1] ?? './'
|
||||||
|
|
||||||
if ((!url.startsWith('http://') && !url.startsWith('https://')) || url.startsWith('mailto:')) {
|
if ((!url.startsWith('http://') && !url.startsWith('https://')) || url.startsWith('mailto:')) {
|
||||||
|
@ -16,7 +17,7 @@ showdown.extension('openExternalInNewTab', {
|
||||||
}
|
}
|
||||||
|
|
||||||
const { hostname } = new URL(url)
|
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.replace(matches[0], `href="${url}" target="_blank" rel="noopener noreferrer">`)
|
||||||
: text
|
: text
|
||||||
}
|
}
|
||||||
|
|
Ładowanie…
Reference in New Issue