Skip to content

Commit

Permalink
Allow empty key name in each iteration
Browse files Browse the repository at this point in the history
Fixes #1021
  • Loading branch information
kpdecker committed Aug 1, 2015
1 parent 2a85106 commit 1bb640b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/handlebars/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ function registerDefaultHelpers(instance) {
// We're running the iterations one step out of sync so we can detect
// the last iteration without have to scan the object twice and create
// an itermediate keys array.
if (priorKey) {
if (priorKey !== undefined) {
execIteration(priorKey, i - 1);
}
priorKey = key;
Expand Down
10 changes: 10 additions & 0 deletions spec/regressions.js
Original file line number Diff line number Diff line change
Expand Up @@ -172,4 +172,14 @@ describe('Regressions', function() {
var result = template(context);
equals(result, 'foo');
});

it('GH-1021: Each empty string key', function() {
var data = {
'': 'foo',
'name': 'Chris',
'value': 10000
};

shouldCompileTo('{{#each data}}Key: {{@key}}\n{{/each}}', {data: data}, 'Key: \nKey: name\nKey: value\n');
});
});

0 comments on commit 1bb640b

Please sign in to comment.