Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion lib/handlebars/compiler/javascript-compiler.js
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,10 @@ JavaScriptCompiler.prototype = {
// Otherwise, the empty string is appended
append: function () {
if (this.isInline()) {
this.replaceStack((current) => [' != null ? ', current, ' : ""']);
// Coerce non-null values to a String so that adjacent buffer appends are
// concatenated rather than combined by the merge `+` (e.g. numeric values
// such as `{{a}}{{b}}` with `noEscape` must yield "12", not 3).
this.replaceStack((current) => [' != null ? "" + ', current, ' : ""']);

this.pushSource(this.appendToBuffer(this.popStack()));
} else {
Expand Down
16 changes: 16 additions & 0 deletions spec/basic.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,22 @@ describe('basic context', function () {
.toCompileTo('num: 0');
});

it('does not add adjacent numeric values with noEscape or raw mustaches', function () {
expectTemplate('{{a}}{{b}}')
.withCompileOptions({ noEscape: true })
.withInput({ a: 1, b: 2 })
.toCompileTo('12');

expectTemplate('{{a}}{{b}}{{c}}')
.withCompileOptions({ noEscape: true })
.withInput({ a: 1, b: 2, c: 3 })
.toCompileTo('123');

expectTemplate('{{{a}}}{{{b}}}')
.withInput({ a: 1, b: 2 })
.toCompileTo('12');
});

it('false', function () {
/* eslint-disable no-new-wrappers */
expectTemplate('val1: {{val1}}, val2: {{val2}}')
Expand Down