diff --git a/lib/handlebars/compiler/compiler.js b/lib/handlebars/compiler/compiler.js index 1aba34b4e..1303d8fc4 100644 --- a/lib/handlebars/compiler/compiler.js +++ b/lib/handlebars/compiler/compiler.js @@ -179,7 +179,12 @@ Compiler.prototype = { this.opcode('pushContext'); } - this.opcode('invokePartial', partialName.name, partial.indent || ''); + var indent = partial.indent || ''; + if (this.options.preventIndent && indent) { + this.opcode('appendContent', indent); + indent = ''; + } + this.opcode('invokePartial', partialName.name, indent); this.opcode('append'); }, diff --git a/spec/env/common.js b/spec/env/common.js index 92cc61123..62edf1d8b 100644 --- a/spec/env/common.js +++ b/spec/env/common.js @@ -18,7 +18,7 @@ global.compileWithPartials = function(string, hashOrArray, partials) { ary = []; ary.push(hashOrArray[0]); ary.push({ helpers: hashOrArray[1], partials: hashOrArray[2] }); - options = {compat: hashOrArray[3]}; + options = typeof hashOrArray[3] === 'object' ? hashOrArray[3] : {compat: hashOrArray[3]}; if (hashOrArray[4] != null) { options.data = !!hashOrArray[4]; ary[1].data = hashOrArray[4]; diff --git a/spec/partials.js b/spec/partials.js index 20187f81d..9c0be4002 100644 --- a/spec/partials.js +++ b/spec/partials.js @@ -167,6 +167,14 @@ describe('partials', function() { shouldCompileToWithPartials(string, [hash, {}, {dude: dude, url: url}], true, "Dudes:\n Yehuda\n http://yehuda!\n Alan\n http://alan!\n"); }); + it("prevent nested indented partials", function() { + var string = "Dudes:\n{{#dudes}}\n {{>dude}}\n{{/dudes}}"; + var dude = "{{name}}\n {{> url}}"; + var url = "{{url}}!\n"; + var hash = {dudes: [{name: "Yehuda", url: "http://yehuda"}, {name: "Alan", url: "http://alan"}]}; + shouldCompileToWithPartials(string, [hash, {}, {dude: dude, url: url}, {preventIndent: true}], true, + "Dudes:\n Yehuda\n http://yehuda!\n Alan\n http://alan!\n"); + }); }); describe('compat mode', function() {