Skip to content

Commit

Permalink
Ignore empty when iterating on sparse arrays
Browse files Browse the repository at this point in the history
Fixes #1065
  • Loading branch information
kpdecker committed Aug 4, 2015
1 parent 0de8dac commit 06d515a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
6 changes: 6 additions & 0 deletions lib/handlebars/helpers/each.js
Expand Up @@ -25,6 +25,12 @@ export default function(instance) {
}

function execIteration(field, index, last) {
// Don't iterate over undefined values since we can't execute blocks against them
// in non-strict (js) mode.
if (context[field] == null) {
return;
}

if (data) {
data.key = field;
data.index = index;
Expand Down
7 changes: 7 additions & 0 deletions spec/regressions.js
Expand Up @@ -196,4 +196,11 @@ describe('Regressions', function() {

shouldCompileToWithPartials(root, [{}, helpers, partials], true, '<partial>');
});

it('GH-1065: Sparse arrays', function() {
var array = [];
array[1] = 'foo';
array[3] = 'bar';
shouldCompileTo('{{#each array}}{{@index}}{{.}}{{/each}}', {array: array}, '1foo3bar');
});
});

0 comments on commit 06d515a

Please sign in to comment.