diff options
author | kpdecker <kpdecker@gmail.com> | 2015-09-23 21:17:57 -0500 |
---|---|---|
committer | kpdecker <kpdecker@gmail.com> | 2015-09-23 21:17:57 -0500 |
commit | fffb5a985f8ff7cd75f2c16b37b69f7ddd3ba9a0 (patch) | |
tree | f43a388545445d40e0187db7993c9bf30c4507dd /spec/regressions.js | |
parent | 08781798f564a68abee11c74e2b98272657b2a56 (diff) | |
download | handlebars.js-fffb5a985f8ff7cd75f2c16b37b69f7ddd3ba9a0.zip handlebars.js-fffb5a985f8ff7cd75f2c16b37b69f7ddd3ba9a0.tar.gz handlebars.js-fffb5a985f8ff7cd75f2c16b37b69f7ddd3ba9a0.tar.bz2 |
Fix iteration over undefined values
Allow for iteration on undefined values, but special case undefined and null to prevent rendering errors when not running in strict mode.
Fixes #1093
Diffstat (limited to 'spec/regressions.js')
-rw-r--r-- | spec/regressions.js | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/spec/regressions.js b/spec/regressions.js index cca126e..931fc4b 100644 --- a/spec/regressions.js +++ b/spec/regressions.js @@ -204,6 +204,24 @@ describe('Regressions', function() { shouldCompileTo('{{#each array}}{{@index}}{{.}}{{/each}}', {array: array}, '1foo3bar'); }); + it('GH-1093: Undefined helper context', function() { + var obj = {foo: undefined, bar: 'bat'}; + var helpers = { + helper: function() { + // It's valid to execute a block against an undefined context, but + // helpers can not do so, so we expect to have an empty object here; + for (var name in this) { + if (this.hasOwnProperty(name)) { + return 'found'; + } + } + return 'not'; + } + }; + + shouldCompileTo('{{#each obj}}{{{helper}}}{{.}}{{/each}}', [{obj: obj}, helpers], 'notfoundbat'); + }); + it('should support multiple levels of inline partials', function() { var string = '{{#> layout}}{{#*inline "subcontent"}}subcontent{{/inline}}{{/layout}}'; var partials = { |