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:
@@ -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;
|
||||
|
||||
|
||||
@@ -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>');
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user