Skip to content

Commit

Permalink
Merge pull request #1087 from denniskuczynski/each_object_empty_strin…
Browse files Browse the repository at this point in the history
…g_key

Fix #each when last object entry has empty key
  • Loading branch information
kpdecker committed Aug 30, 2015
2 parents e70430d + 7c896a0 commit 0f5061e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/handlebars/helpers/each.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ export default function(instance) {
i++;
}
}
if (priorKey) {
if (priorKey !== undefined) {
execIteration(priorKey, i - 1, true);
}
}
Expand Down
10 changes: 10 additions & 0 deletions spec/builtins.js
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,16 @@ describe('builtin helpers', function() {
'each with array function argument ignores the contents when empty');
});

it('each object when last key is an empty string', function() {
var string = '{{#each goodbyes}}{{@index}}. {{text}}! {{/each}}cruel {{world}}!';
var hash = {goodbyes: {'a': {text: 'goodbye'}, b: {text: 'Goodbye'}, '': {text: 'GOODBYE'}}, world: 'world'};

var template = CompilerContext.compile(string);
var result = template(hash);

equal(result, '0. goodbye! 1. Goodbye! 2. GOODBYE! cruel world!', 'Empty string key is not skipped');
});

it('data passed to helpers', function() {
var string = '{{#each letters}}{{this}}{{detectDataInsideEach}}{{/each}}';
var hash = {letters: ['a', 'b', 'c']};
Expand Down

0 comments on commit 0f5061e

Please sign in to comment.