diff options
author | kpdecker <kpdecker@gmail.com> | 2015-08-03 16:08:23 -0500 |
---|---|---|
committer | kpdecker <kpdecker@gmail.com> | 2015-08-03 16:08:23 -0500 |
commit | 8e868ab22509c6ca5f5e7419e61c10e6e771b954 (patch) | |
tree | 9ee703c5fd3d8dac44ea964f49398a2ad98e1a42 | |
parent | 5d4b8da344ab5060205678375df298a3d738e862 (diff) | |
download | handlebars.js-8e868ab22509c6ca5f5e7419e61c10e6e771b954.zip handlebars.js-8e868ab22509c6ca5f5e7419e61c10e6e771b954.tar.gz handlebars.js-8e868ab22509c6ca5f5e7419e61c10e6e771b954.tar.bz2 |
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.
-rw-r--r-- | lib/handlebars/runtime.js | 2 | ||||
-rw-r--r-- | spec/regressions.js | 14 |
2 files changed, 15 insertions, 1 deletions
diff --git a/lib/handlebars/runtime.js b/lib/handlebars/runtime.js index bc12fc9..9dae284 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 f041070..009fec9 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}}<partial>{{/wrap}}' + }; + var helpers = { + wrap: function(options) { + return new Handlebars.SafeString(options.fn()); + } + }; + + shouldCompileToWithPartials(root, [{}, helpers, partials], true, '<partial>'); + }); }); |