From fb8baa5f53a8337a12bfd236c1988399a439db04 Mon Sep 17 00:00:00 2001 From: Tomasz Pluskiewicz Date: Mon, 4 Jan 2021 12:49:55 +0100 Subject: [PATCH] Do not replace when variable is not found This fixes a problem that JS string interpolation inside code blocks gets all replaced with the variables. Which essentially replaces them with empty string everywhere unless the interpolated variable is also present in the variables file --- src/index.js | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/index.js b/src/index.js index 86cd853..4d006c8 100644 --- a/src/index.js +++ b/src/index.js @@ -8,12 +8,15 @@ function resolveVar(v){ if (variablesFile && variablesObj == null){ initVariablesObj(); } + + let replacement = [] + if (variablesFileType == "xml"){ - return resolveXMLVar(v); + replacement = resolveXMLVar(v); }else if (variablesFileType == "json"){ - return resolveJSONVar(v); + replacement = resolveJSONVar(v); } - return "${"+v+"}" + return replacement.length === 0 ? "${"+v+"}" : replacement } function resolveJSONVar(v){