Skip to content

Commit

Permalink
Ensure that programs always return strings
Browse files Browse the repository at this point in the history
Fixes #1838
  • Loading branch information
nknapp committed Aug 6, 2023
1 parent 520e1d5 commit b0c0154
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/handlebars/compiler/javascript-compiler.js
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ JavaScriptCompiler.prototype = {

if (appendOnly) {
if (bufferStart) {
bufferStart.prepend('return ');
bufferStart.prepend('return "" + ');
bufferEnd.add(';');
} else if (!sourceSeen) {
this.source.push('return "";');
Expand Down
21 changes: 21 additions & 0 deletions spec/javascript-compiler.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ describe('javascript-compiler api', function() {
.toCompileTo('food');
});
});

describe('#compilerInfo', function() {
var $superCheck, $superInfo;
beforeEach(function() {
Expand All @@ -58,6 +59,7 @@ describe('javascript-compiler api', function() {
.toCompileTo('food ');
});
});

describe('buffer', function() {
var $superAppend, $superCreate;
beforeEach(function() {
Expand Down Expand Up @@ -116,4 +118,23 @@ describe('javascript-compiler api', function() {
});
});
});

describe('options', function() {
it('should append `noEscape` statements as string', function() {
expectTemplate('{{a}}{{b}}')
.withCompileOptions({ noEscape: true })
.withInput({ a: 1, b: 1 })
.toCompileTo('11');
});

it('should append `noEscape` statements as string in a block', function() {
expectTemplate('{{#block}}{{a}}{{b}}{{/block}}')
.withCompileOptions({ noEscape: true })
.withHelper('block', function(options) {
return options.fn(this);
})
.withInput({ a: 1, b: 1 })
.toCompileTo('11');
});
});
});

0 comments on commit b0c0154

Please sign in to comment.