From 5691be6fc02ab5ea02dc70440b086aa91bce9b89 Mon Sep 17 00:00:00 2001 From: Andrew Kingston Date: Tue, 12 Oct 2021 15:32:43 +0100 Subject: [PATCH] Ensure null or empty values don't cause raw JS to appear when executing JS HBS helper --- packages/string-templates/src/helpers/javascript.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/packages/string-templates/src/helpers/javascript.js b/packages/string-templates/src/helpers/javascript.js index cba3966213..2fca180d14 100644 --- a/packages/string-templates/src/helpers/javascript.js +++ b/packages/string-templates/src/helpers/javascript.js @@ -36,7 +36,11 @@ module.exports.processJS = (handlebars, context) => { // Create a sandbox with out context and run the JS vm.createContext(sandboxContext) - return vm.runInNewContext(js, sandboxContext) + const result = vm.runInNewContext(js, sandboxContext) + if (result == null || result === "") { + return " " + } + return result } catch (error) { return "Error while executing JS" }