From 768ddbd6616f47a7a77ae2046775c43c2fe3e5ee Mon Sep 17 00:00:00 2001 From: kpdecker Date: Fri, 11 Mar 2016 22:16:18 -0600 Subject: 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 #1194 --- lib/handlebars/compiler/javascript-compiler.js | 2 +- spec/regressions.js | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/lib/handlebars/compiler/javascript-compiler.js b/lib/handlebars/compiler/javascript-compiler.js index 4e4f288..ed1b83e 100644 --- a/lib/handlebars/compiler/javascript-compiler.js +++ b/lib/handlebars/compiler/javascript-compiler.js @@ -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; diff --git a/spec/regressions.js b/spec/regressions.js index 4a2a55c..4dc2ac8 100644 --- a/spec/regressions.js +++ b/spec/regressions.js @@ -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'); + }); }); -- cgit v1.1