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.
This commit is contained in:
kpdecker
2015-08-03 16:08:23 -05:00
parent 5d4b8da344
commit 8e868ab225
2 changed files with 15 additions and 1 deletions
+1 -1
View File
@@ -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;
+14
View File
@@ -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>');
});
});