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
  • Loading branch information
kpdecker committed Mar 12, 2016
1 parent 06baeae commit 768ddbd
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 @@ -503,7 +503,7 @@ JavaScriptCompiler.prototype = {
if (this.hash) {
this.hashes.push(this.hash);
}
this.hash = {values: [], types: [], contexts: [], ids: []};
this.hash = {values: {}};
},
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 @@ -277,4 +277,15 @@ describe('Regressions', function() {

shouldCompileTo(string, { listOne: ['a'], listTwo: ['b']}, 'ab', '');
});

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 768ddbd

Please sign in to comment.