From 1bb640be412f20d74db7af476152a081073aa21a Mon Sep 17 00:00:00 2001 From: kpdecker Date: Sat, 1 Aug 2015 16:04:40 -0500 Subject: [PATCH] Allow empty key name in each iteration Fixes #1021 --- lib/handlebars/base.js | 2 +- spec/regressions.js | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/lib/handlebars/base.js b/lib/handlebars/base.js index c2f14eb4d..c7dc08151 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 247c1c9b3..f04107046 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'); + }); });