Skip to content

Commit

Permalink
Always return string responses
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
kpdecker committed Aug 3, 2015
1 parent 5d4b8da commit 8e868ab
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/handlebars/runtime.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
14 changes: 14 additions & 0 deletions spec/regressions.js
Original file line number Diff line number Diff line change
Expand Up @@ -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>');
});
});

0 comments on commit 8e868ab

Please sign in to comment.