♿ Remove invalid js in meta head code
This commit is contained in:
@ -498,6 +498,7 @@ const injectTryCatch = (headCode: string) => {
|
||||
const wrappedTag = tag.replace(
|
||||
/(<script\b[^>]*>)([\s\S]*?)(<\/script>)/gi,
|
||||
function (_, openingTag, content, closingTag) {
|
||||
if (!isValidJsSyntax(content)) return ''
|
||||
return `${openingTag}
|
||||
try {
|
||||
${content}
|
||||
@ -512,3 +513,12 @@ ${closingTag}`
|
||||
}
|
||||
return headCode
|
||||
}
|
||||
|
||||
const isValidJsSyntax = (snippet: string): boolean => {
|
||||
try {
|
||||
new Function(snippet)
|
||||
return true
|
||||
} catch (err) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user