summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorkpdecker <kpdecker@gmail.com>2016-03-11 22:16:18 -0600
committerkpdecker <kpdecker@gmail.com>2016-03-11 22:16:18 -0600
commit768ddbd6616f47a7a77ae2046775c43c2fe3e5ee (patch)
tree8e49125f141e9f2ae5c9e5a2b52616229a10e9ab
parent06baeaebfd7e4b3c4c44397c53f189b7dae3de03 (diff)
downloadhandlebars.js-768ddbd6616f47a7a77ae2046775c43c2fe3e5ee.zip
handlebars.js-768ddbd6616f47a7a77ae2046775c43c2fe3e5ee.tar.gz
handlebars.js-768ddbd6616f47a7a77ae2046775c43c2fe3e5ee.tar.bz2
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
-rw-r--r--lib/handlebars/compiler/javascript-compiler.js2
-rw-r--r--spec/regressions.js11
2 files changed, 12 insertions, 1 deletions
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');
+ });
});