Skip to content

Commit

Permalink
Fix #428 nested if else rendering
Browse files Browse the repository at this point in the history
The program equality checker was not taking children into account
when determining equality, causing breakages under similar cases.
  • Loading branch information
kpdecker committed Feb 16, 2013
1 parent 1f00504 commit d6f146f
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 0 deletions.
11 changes: 11 additions & 0 deletions dist/handlebars.js
Original file line number Diff line number Diff line change
Expand Up @@ -897,6 +897,17 @@ Compiler.prototype = {
}
}
}

len = this.children.length;
if (other.children.length !== len) {
return false;
}
for (i = 0; i < len; i++) {
if (!this.children[i].equals(other.children[i])) {
return false;
}
}

return true;
},

Expand Down
11 changes: 11 additions & 0 deletions lib/handlebars/compiler/compiler.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,17 @@ Compiler.prototype = {
}
}
}

len = this.children.length;
if (other.children.length !== len) {
return false;
}
for (i = 0; i < len; i++) {
if (!this.children[i].equals(other.children[i])) {
return false;
}
}

return true;
},

Expand Down
13 changes: 13 additions & 0 deletions spec/qunit_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1384,3 +1384,16 @@ test('GH-408: Multiple loops fail', function() {
var result = template(context);
equals(result, "John DoeJane DoeJohn DoeJane DoeJohn DoeJane Doe", 'It should output multiple times');
});

test('GS-428: Nested if else rendering', function() {
var succeedingTemplate = '{{#inverse}} {{#blk}} Unexpected {{/blk}} {{else}} {{#blk}} Expected {{/blk}} {{/inverse}}';
var failingTemplate = '{{#inverse}} {{#blk}} Unexpected {{/blk}} {{else}} {{#blk}} Expected {{/blk}} {{/inverse}}';

var helpers = {
blk: function(block) { return block.fn(''); },
inverse: function(block) { return block.inverse(''); }
};

shouldCompileTo(succeedingTemplate, [{}, helpers], ' Expected ');
shouldCompileTo(failingTemplate, [{}, helpers], ' Expected ');
});

0 comments on commit d6f146f

Please sign in to comment.