From 8e868ab22509c6ca5f5e7419e61c10e6e771b954 Mon Sep 17 00:00:00 2001 From: kpdecker Date: Mon, 3 Aug 2015 16:08:23 -0500 Subject: [PATCH] Always return string responses Certain optimizations for simple templates could result in objects returned by helpers returned rather than their string representation, resulting in some odd edge cases. This ensures that strings are always returned from the API for consistency. Fixes #1054. --- lib/handlebars/runtime.js | 2 +- spec/regressions.js | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/lib/handlebars/runtime.js b/lib/handlebars/runtime.js index bc12fc9fd..9dae28407 100644 --- a/lib/handlebars/runtime.js +++ b/lib/handlebars/runtime.js @@ -142,7 +142,7 @@ export function template(templateSpec, env) { } } - return templateSpec.main.call(container, context, container.helpers, container.partials, data, blockParams, depths); + return '' + templateSpec.main.call(container, context, container.helpers, container.partials, data, blockParams, depths); } ret.isTop = true; diff --git a/spec/regressions.js b/spec/regressions.js index f04107046..009fec90b 100644 --- a/spec/regressions.js +++ b/spec/regressions.js @@ -182,4 +182,18 @@ describe('Regressions', function() { shouldCompileTo('{{#each data}}Key: {{@key}}\n{{/each}}', {data: data}, 'Key: \nKey: name\nKey: value\n'); }); + + it('GH-1054: Should handle simple safe string responses', function() { + var root = '{{#wrap}}{{>partial}}{{/wrap}}'; + var partials = { + partial: '{{#wrap}}{{/wrap}}' + }; + var helpers = { + wrap: function(options) { + return new Handlebars.SafeString(options.fn()); + } + }; + + shouldCompileToWithPartials(root, [{}, helpers, partials], true, ''); + }); });