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