Skip to content

Commit 7fcf9d2

Browse files
kpdeckernknapp
authored andcommitted
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 (cherry picked from commit 768ddbd)
1 parent c76ded8 commit 7fcf9d2

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
@@ -543,7 +543,7 @@ JavaScriptCompiler.prototype = {
543543
if (this.hash) {
544544
this.hashes.push(this.hash);
545545
}
546-
this.hash = {values: [], types: [], contexts: [], ids: []};
546+
this.hash = {values: {}, types: [], contexts: [], ids: []};
547547
},
548548
popHash: function() {
549549
let hash = this.hash;

spec/regressions.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -323,4 +323,15 @@ describe('Regressions', function() {
323323
}, 'useData': true});
324324
}
325325
});
326+
327+
it('should allow hash with protected array names', function() {
328+
var obj = {array: [1], name: 'John'};
329+
var helpers = {
330+
helpa: function(options) {
331+
return options.hash.length;
332+
}
333+
};
334+
335+
shouldCompileTo('{{helpa length="foo"}}', [obj, helpers], 'foo');
336+
});
326337
});

0 commit comments

Comments
 (0)