From 0521d26c603327ab953d58a2bcca9818f5fb2d62 Mon Sep 17 00:00:00 2001 From: YISH Date: Mon, 26 Feb 2024 11:03:35 +0800 Subject: [PATCH 1/3] Fix CustomFunction deserializing escaped JSON strings --- .../utilities/CustomFunction/CustomFunction.ts | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/packages/components/nodes/utilities/CustomFunction/CustomFunction.ts b/packages/components/nodes/utilities/CustomFunction/CustomFunction.ts index 4ab2a6f2ab8..2ec6074aa8a 100644 --- a/packages/components/nodes/utilities/CustomFunction/CustomFunction.ts +++ b/packages/components/nodes/utilities/CustomFunction/CustomFunction.ts @@ -90,13 +90,15 @@ class CustomFunction_Utilities implements INode { // Some values might be a stringified JSON, parse it for (const key in inputVars) { - if (typeof inputVars[key] === 'string' && inputVars[key].startsWith('{') && inputVars[key].endsWith('}')) { + value = handleEscapeCharacters(value, true) + if (value.startsWith('{') && value.endsWith('}')) { try { - inputVars[key] = JSON.parse(inputVars[key]) + value = JSON.parse(value) } catch (e) { - continue + // ignore } } + inputVars[key] = value } let sandbox: any = { $input: input } @@ -105,11 +107,7 @@ class CustomFunction_Utilities implements INode { if (Object.keys(inputVars).length) { for (const item in inputVars) { - let value = inputVars[item] - if (typeof value === 'string') { - value = handleEscapeCharacters(value, true) - } - sandbox[`$${item}`] = value + sandbox[`$${item}`] = inputVars[item] } } From 735425e902a77cb8e08ae101eabc1aba51c7b5ed Mon Sep 17 00:00:00 2001 From: YISH Date: Mon, 26 Feb 2024 11:05:29 +0800 Subject: [PATCH 2/3] Update CustomFunction.ts --- .../utilities/CustomFunction/CustomFunction.ts | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/packages/components/nodes/utilities/CustomFunction/CustomFunction.ts b/packages/components/nodes/utilities/CustomFunction/CustomFunction.ts index 2ec6074aa8a..9c1469e0125 100644 --- a/packages/components/nodes/utilities/CustomFunction/CustomFunction.ts +++ b/packages/components/nodes/utilities/CustomFunction/CustomFunction.ts @@ -90,15 +90,18 @@ class CustomFunction_Utilities implements INode { // Some values might be a stringified JSON, parse it for (const key in inputVars) { - value = handleEscapeCharacters(value, true) - if (value.startsWith('{') && value.endsWith('}')) { - try { - value = JSON.parse(value) - } catch (e) { - // ignore + let value = inputVars[key] + if (typeof value === 'string') { + value = handleEscapeCharacters(value, true) + if (value.startsWith('{') && value.endsWith('}')) { + try { + value = JSON.parse(value) + } catch (e) { + // ignore + } } + inputVars[key] = value } - inputVars[key] = value } let sandbox: any = { $input: input } From a412bcc84eb3957a282a45393a1dae2bbc584163 Mon Sep 17 00:00:00 2001 From: YISH Date: Thu, 29 Feb 2024 19:34:30 +0800 Subject: [PATCH 3/3] Update IfElseFunction.ts --- .../IfElseFunction/IfElseFunction.ts | 21 ++++++++++--------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/packages/components/nodes/utilities/IfElseFunction/IfElseFunction.ts b/packages/components/nodes/utilities/IfElseFunction/IfElseFunction.ts index 1c5c0b7debb..1e61616c7f1 100644 --- a/packages/components/nodes/utilities/IfElseFunction/IfElseFunction.ts +++ b/packages/components/nodes/utilities/IfElseFunction/IfElseFunction.ts @@ -101,12 +101,17 @@ class IfElseFunction_Utilities implements INode { // Some values might be a stringified JSON, parse it for (const key in inputVars) { - if (typeof inputVars[key] === 'string' && inputVars[key].startsWith('{') && inputVars[key].endsWith('}')) { - try { - inputVars[key] = JSON.parse(inputVars[key]) - } catch (e) { - continue + let value = inputVars[key] + if (typeof value === 'string') { + value = handleEscapeCharacters(value, true) + if (value.startsWith('{') && value.endsWith('}')) { + try { + value = JSON.parse(value) + } catch (e) { + // ignore + } } + inputVars[key] = value } } @@ -116,11 +121,7 @@ class IfElseFunction_Utilities implements INode { if (Object.keys(inputVars).length) { for (const item in inputVars) { - let value = inputVars[item] - if (typeof value === 'string') { - value = handleEscapeCharacters(value, true) - } - sandbox[`$${item}`] = value + sandbox[`$${item}`] = inputVars[item] } }