Skip to content

Commit 768ddbd

Browse files
committed
Use objects for hash value tracking
The use of arrays was incorrect for the data type and causing problems when hash keys conflicted with array behaviors. Fixes handlebars-lang#1194
1 parent 06baeae commit 768ddbd

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

lib/handlebars/compiler/javascript-compiler.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -503,7 +503,7 @@ JavaScriptCompiler.prototype = {
503503
if (this.hash) {
504504
this.hashes.push(this.hash);
505505
}
506-
this.hash = {values: [], types: [], contexts: [], ids: []};
506+
this.hash = {values: {}};
507507
},
508508
popHash: function() {
509509
let hash = this.hash;

spec/regressions.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,4 +277,15 @@ describe('Regressions', function() {
277277

278278
shouldCompileTo(string, { listOne: ['a'], listTwo: ['b']}, 'ab', '');
279279
});
280+
281+
it('should allow hash with protected array names', function() {
282+
var obj = {array: [1], name: 'John'};
283+
var helpers = {
284+
helpa: function(options) {
285+
return options.hash.length;
286+
}
287+
};
288+
289+
shouldCompileTo('{{helpa length="foo"}}', [obj, helpers], 'foo');
290+
});
280291
});

0 commit comments

Comments
 (0)