Merge pull request #1814 from mokeyish/patch-3

Fix CustomFunction deserializing escaped JSON strings
This commit is contained in:
Henry Heng
2024-03-01 16:41:43 +08:00
committed by GitHub
2 changed files with 22 additions and 20 deletions
@@ -90,13 +90,18 @@ class CustomFunction_Utilities implements INode {
// Some values might be a stringified JSON, parse it // Some values might be a stringified JSON, parse it
for (const key in inputVars) { for (const key in inputVars) {
if (typeof inputVars[key] === 'string' && inputVars[key].startsWith('{') && inputVars[key].endsWith('}')) { let value = inputVars[key]
if (typeof value === 'string') {
value = handleEscapeCharacters(value, true)
if (value.startsWith('{') && value.endsWith('}')) {
try { try {
inputVars[key] = JSON.parse(inputVars[key]) value = JSON.parse(value)
} catch (e) { } catch (e) {
continue // ignore
} }
} }
inputVars[key] = value
}
} }
let sandbox: any = { $input: input } let sandbox: any = { $input: input }
@@ -105,11 +110,7 @@ class CustomFunction_Utilities implements INode {
if (Object.keys(inputVars).length) { if (Object.keys(inputVars).length) {
for (const item in inputVars) { for (const item in inputVars) {
let value = inputVars[item] sandbox[`$${item}`] = inputVars[item]
if (typeof value === 'string') {
value = handleEscapeCharacters(value, true)
}
sandbox[`$${item}`] = value
} }
} }
@@ -101,13 +101,18 @@ class IfElseFunction_Utilities implements INode {
// Some values might be a stringified JSON, parse it // Some values might be a stringified JSON, parse it
for (const key in inputVars) { for (const key in inputVars) {
if (typeof inputVars[key] === 'string' && inputVars[key].startsWith('{') && inputVars[key].endsWith('}')) { let value = inputVars[key]
if (typeof value === 'string') {
value = handleEscapeCharacters(value, true)
if (value.startsWith('{') && value.endsWith('}')) {
try { try {
inputVars[key] = JSON.parse(inputVars[key]) value = JSON.parse(value)
} catch (e) { } catch (e) {
continue // ignore
} }
} }
inputVars[key] = value
}
} }
let sandbox: any = { $input: input } let sandbox: any = { $input: input }
@@ -116,11 +121,7 @@ class IfElseFunction_Utilities implements INode {
if (Object.keys(inputVars).length) { if (Object.keys(inputVars).length) {
for (const item in inputVars) { for (const item in inputVars) {
let value = inputVars[item] sandbox[`$${item}`] = inputVars[item]
if (typeof value === 'string') {
value = handleEscapeCharacters(value, true)
}
sandbox[`$${item}`] = value
} }
} }