From 4ec8376efa87d93745a6dbecabdf9ab3f8a5ff27 Mon Sep 17 00:00:00 2001 From: Henry Heng Date: Tue, 4 Jun 2024 15:44:27 +0100 Subject: [PATCH] Bugfix/get rid of double quotes when replacing variable value (#2577) get rid of double quotes when replacing variable value --- packages/server/src/utils/index.ts | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/packages/server/src/utils/index.ts b/packages/server/src/utils/index.ts index c9ea2682..0fd7f290 100644 --- a/packages/server/src/utils/index.ts +++ b/packages/server/src/utils/index.ts @@ -782,7 +782,13 @@ export const getVariableValue = ( const variableValue = variableDict[path] // Replace all occurrence if (typeof variableValue === 'object') { - returnVal = returnVal.split(path).join(JSON.stringify(JSON.stringify(variableValue))) + const stringifiedValue = JSON.stringify(JSON.stringify(variableValue)) + if (stringifiedValue.startsWith('"') && stringifiedValue.endsWith('"')) { + // get rid of the double quotes + returnVal = returnVal.split(path).join(stringifiedValue.substring(1, stringifiedValue.length - 1)) + } else { + returnVal = returnVal.split(path).join(JSON.stringify(variableValue).replace(/"/g, '\\"')) + } } else { returnVal = returnVal.split(path).join(variableValue) }