优化转义规则

This commit is contained in:
fofolee
2024-03-04 16:42:03 +08:00
parent fbae2864b2
commit 10d7ab200e
2 changed files with 29 additions and 21 deletions

View File

@@ -2,17 +2,11 @@
* 所有的特殊变量
*/
let escapeItem = item => {
if (typeof item === 'number') return item
item = typeof item === 'object' ? JSON.stringify(item) : item.replace(/\\/g, '\\\\')
return item.replace('$', '$$$')
}
let handlingJsonVar = (jsonVar, name, payload) => {
try {
return escapeItem(window.evalCodeInSandbox(jsonVar.slice(2, -2), {
return window.evalCodeInSandbox(jsonVar.slice(2, -2), {
[name]: payload
}))
})
} catch (e) {
return utools.showNotification(e)
}