Skip to content

Commit

Permalink
Use objects for hash value tracking
Browse files Browse the repository at this point in the history
The use of arrays was incorrect for the data type and causing problems when hash keys conflicted with array behaviors.

Fixes #1194

(cherry picked from commit 768ddbd)
  • Loading branch information
kpdecker authored and nknapp committed Oct 27, 2019
1 parent c76ded8 commit 7fcf9d2
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/handlebars/compiler/javascript-compiler.js
Original file line number Diff line number Diff line change
Expand Up @@ -543,7 +543,7 @@ JavaScriptCompiler.prototype = {
if (this.hash) {
this.hashes.push(this.hash);
}
this.hash = {values: [], types: [], contexts: [], ids: []};
this.hash = {values: {}, types: [], contexts: [], ids: []};
},
popHash: function() {
let hash = this.hash;
Expand Down
11 changes: 11 additions & 0 deletions spec/regressions.js
Original file line number Diff line number Diff line change
Expand Up @@ -323,4 +323,15 @@ describe('Regressions', function() {
}, 'useData': true});
}
});

it('should allow hash with protected array names', function() {
var obj = {array: [1], name: 'John'};
var helpers = {
helpa: function(options) {
return options.hash.length;
}
};

shouldCompileTo('{{helpa length="foo"}}', [obj, helpers], 'foo');
});
});

0 comments on commit 7fcf9d2

Please sign in to comment.