diff options
author | kpdecker <kpdecker@gmail.com> | 2015-08-01 16:04:40 -0500 |
---|---|---|
committer | kpdecker <kpdecker@gmail.com> | 2015-08-01 16:04:40 -0500 |
commit | 1bb640be412f20d74db7af476152a081073aa21a (patch) | |
tree | 78c122fab3dbaef17747fd4ee4f1f42b213954e2 | |
parent | 2a851067b99c3932e471f5fc1a2d40dc25a084c4 (diff) | |
download | handlebars.js-1bb640be412f20d74db7af476152a081073aa21a.zip handlebars.js-1bb640be412f20d74db7af476152a081073aa21a.tar.gz handlebars.js-1bb640be412f20d74db7af476152a081073aa21a.tar.bz2 |
Allow empty key name in each iteration
Fixes #1021
-rw-r--r-- | lib/handlebars/base.js | 2 | ||||
-rw-r--r-- | spec/regressions.js | 10 |
2 files changed, 11 insertions, 1 deletions
diff --git a/lib/handlebars/base.js b/lib/handlebars/base.js index c2f14eb..c7dc081 100644 --- a/lib/handlebars/base.js +++ b/lib/handlebars/base.js @@ -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; diff --git a/spec/regressions.js b/spec/regressions.js index 247c1c9..f041070 100644 --- a/spec/regressions.js +++ b/spec/regressions.js @@ -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'); + }); }); |