From 051b49efdb29ea9611d3dccfcfed53aa29a454df Mon Sep 17 00:00:00 2001 From: Robin Ward Date: Wed, 4 Oct 2017 12:48:14 -0400 Subject: [PATCH] FIX: Properly encode string literals in hbs compiler --- lib/javascripts/widget-hbs-compiler.js.es6 | 7 ++++++- script/test_hbs_compiler.rb | 2 +- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/lib/javascripts/widget-hbs-compiler.js.es6 b/lib/javascripts/widget-hbs-compiler.js.es6 index 0f84f1c03d6..2561d9362d2 100644 --- a/lib/javascripts/widget-hbs-compiler.js.es6 +++ b/lib/javascripts/widget-hbs-compiler.js.es6 @@ -11,7 +11,12 @@ function sexp(value) { let result = []; value.hash.pairs.forEach(p => { - result.push(`"${p.key}": ${p.value.original}`); + let pValue = p.value.original; + if (p.value.type === "StringLiteral") { + pValue = JSON.stringify(pValue); + } + + result.push(`"${p.key}": ${pValue}`); }); return `{ ${result.join(", ")} }`; diff --git a/script/test_hbs_compiler.rb b/script/test_hbs_compiler.rb index d18a41fc176..773908c5b4c 100644 --- a/script/test_hbs_compiler.rb +++ b/script/test_hbs_compiler.rb @@ -3,7 +3,7 @@ template = <<~HBS {{a}} {{{htmlValue}}} {{#if state.category}} - {{attach widget="category-display" attrs=(hash category=state.category)}} + {{attach widget="category-display" attrs=(hash category=state.category someNumber=123 someString="wat")}} {{/if}} HBS