diff --git a/helpers/decrementVar.js b/helpers/decrementVar.js index f55db63..91f4f82 100644 --- a/helpers/decrementVar.js +++ b/helpers/decrementVar.js @@ -13,7 +13,7 @@ const factory = globals => { globals.storage.variables = {}; } - if (Number.isInteger(globals.storage.variables[key])) { + if (globals.storage.variables.hasOwnProperty(key) &&Number.isInteger(globals.storage.variables[key])) { // Decrement value if it already exists globals.storage.variables[key] -= 1; } else { @@ -26,7 +26,7 @@ const factory = globals => { } // Return current value - return globals.storage.variables[key]; + return globals.storage.variables.hasOwnProperty(key) ? globals.storage.variables[key]: undefined; }; }; diff --git a/helpers/dynamicComponent.js b/helpers/dynamicComponent.js index f403036..15f84c2 100644 --- a/helpers/dynamicComponent.js +++ b/helpers/dynamicComponent.js @@ -19,7 +19,7 @@ const factory = globals => { path = Path.join(path, this['partial']); - if (globals.handlebars.partials[path]) { + if (globals.handlebars.partials[path] && globals.handlebars.partials.hasOwnProperty(path)) { return globals.handlebars.partials[path](this); } }; diff --git a/helpers/getVar.js b/helpers/getVar.js index f6726d0..048273c 100644 --- a/helpers/getVar.js +++ b/helpers/getVar.js @@ -7,7 +7,7 @@ const factory = globals => { throw new Error("getVar helper key must be a string"); } - return globals.storage.variables ? globals.storage.variables[key] : undefined + return globals.storage.variables && globals.storage.variables.hasOwnProperty(key) ? globals.storage.variables[key] : undefined }; }; diff --git a/helpers/incrementVar.js b/helpers/incrementVar.js index a9eef2b..bd953e0 100644 --- a/helpers/incrementVar.js +++ b/helpers/incrementVar.js @@ -13,7 +13,7 @@ const factory = globals => { globals.storage.variables = {}; } - if (Number.isInteger(globals.storage.variables[key])) { + if (globals.storage.variables.hasOwnProperty(key) && Number.isInteger(globals.storage.variables[key])) { // Increment value if it already exists globals.storage.variables[key] += 1; } else { @@ -26,7 +26,7 @@ const factory = globals => { } // Return current value - return globals.storage.variables[key]; + return globals.storage.variables.hasOwnProperty(key) ? globals.storage.variables[key]: undefined; }; }; diff --git a/helpers/pluck.js b/helpers/pluck.js index 80e25f7..68d2ad6 100644 --- a/helpers/pluck.js +++ b/helpers/pluck.js @@ -4,7 +4,7 @@ var _ = require('lodash'); const factory = () => { return function(collection, path) { - return _.map(collection, item => item[path]); + return _.map(collection, item => item.hasOwnProperty(path) ? item[path] : undefined); }; }; diff --git a/spec/helpers/assignVar-getVar.js b/spec/helpers/assignVar-getVar.js index 1a9d671..bb75312 100644 --- a/spec/helpers/assignVar-getVar.js +++ b/spec/helpers/assignVar-getVar.js @@ -83,4 +83,17 @@ describe('assignVar and getVar helpers', function() { done(); }); }); + + it('should return undefined accessing proto/constructor', function(done) { + runTestCases([ + { + input: "{{getVar '__proto__'}}", + output: '', + }, + { + input: "{{getVar 'constructor'}}", + output: '', + }, + ], done); + }); }); diff --git a/spec/helpers/decrementVar.js b/spec/helpers/decrementVar.js index 727f1f9..9cce47b 100644 --- a/spec/helpers/decrementVar.js +++ b/spec/helpers/decrementVar.js @@ -54,4 +54,17 @@ describe('decrementVar helper', function() { }, ], done); }); + + it('should correctly return data accession object proto/constructor', function(done) { + runTestCases([ + { + input: "{{decrementVar '__proto__'}}", + output: '', + }, + { + input: "{{decrementVar 'constructor'}}", + output: '0', + }, + ], done); + }); }); diff --git a/spec/helpers/dynamicComponent.js b/spec/helpers/dynamicComponent.js index a1a98ce..13a9b5d 100644 --- a/spec/helpers/dynamicComponent.js +++ b/spec/helpers/dynamicComponent.js @@ -30,5 +30,18 @@ describe('dynamicComponent helper', function() { }, ], done); }); + + it('should return undefined when accessing proto/constructor', function(done) { + runTestCases([ + { + input: '{{#each fields}}{{dynamicComponent "__proto__"}}{{/each}}', + output: '', + }, + { + input: '{{#each fields}}{{dynamicComponent "constructor"}}{{/each}}', + output: '', + }, + ], done); + }); }); diff --git a/spec/helpers/incrementVar.js b/spec/helpers/incrementVar.js index e67551d..b3c25dc 100644 --- a/spec/helpers/incrementVar.js +++ b/spec/helpers/incrementVar.js @@ -54,4 +54,19 @@ describe('incrementVar helper', function() { }, ], done); }); + + + + it('should correctly return data accession object proto/constructor', function(done) { + runTestCases([ + { + input: "{{incrementVar '__proto__'}}", + output: '', + }, + { + input: "{{incrementVar 'constructor'}}", + output: '0', + }, + ], done); + }); }); diff --git a/spec/helpers/pluck.js b/spec/helpers/pluck.js index bbf3e0a..dcc9a4a 100644 --- a/spec/helpers/pluck.js +++ b/spec/helpers/pluck.js @@ -26,4 +26,17 @@ describe('pluck helper', function() { }, ], done); }); + + it('should return undefined when accessing proto/constructor', function(done) { + runTestCases([ + { + input: '{{pluck users "__proto__"}}', + output: ',', + }, + { + input: '{{pluck users "constructor"}}', + output: ',', + }, + ], done); + }); });