diff options
author | Kevin Decker <kpdecker@gmail.com> | 2015-08-30 17:27:52 -0500 |
---|---|---|
committer | Kevin Decker <kpdecker@gmail.com> | 2015-08-30 17:27:52 -0500 |
commit | 0f5061e44524a431659f0665c4cd7557af9525a0 (patch) | |
tree | b99195a103ac118dfa0264829d1b850cc7fc0073 | |
parent | e70430dd2e41f5bc1a9a077412db7559761ad7d5 (diff) | |
parent | 7c896a074dad733dd60cd789b8f1cec3025d7a4a (diff) | |
download | handlebars.js-0f5061e44524a431659f0665c4cd7557af9525a0.zip handlebars.js-0f5061e44524a431659f0665c4cd7557af9525a0.tar.gz handlebars.js-0f5061e44524a431659f0665c4cd7557af9525a0.tar.bz2 |
Merge pull request #1087 from denniskuczynski/each_object_empty_string_key
Fix #each when last object entry has empty key
-rw-r--r-- | lib/handlebars/helpers/each.js | 2 | ||||
-rw-r--r-- | spec/builtins.js | 10 |
2 files changed, 11 insertions, 1 deletions
diff --git a/lib/handlebars/helpers/each.js b/lib/handlebars/helpers/each.js index d39a300..9b1629b 100644 --- a/lib/handlebars/helpers/each.js +++ b/lib/handlebars/helpers/each.js @@ -68,7 +68,7 @@ export default function(instance) { i++; } } - if (priorKey) { + if (priorKey !== undefined) { execIteration(priorKey, i - 1, true); } } diff --git a/spec/builtins.js b/spec/builtins.js index a7f6204..f06a1ad 100644 --- a/spec/builtins.js +++ b/spec/builtins.js @@ -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']}; |