Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/handlebars/runtime.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ export function template(templateSpec, env) {
// Just add water
let container = {
strict: function (obj, name, loc) {
if (!obj || !(name in obj)) {
if (obj == null || !(name in Object(obj))) {
throw new Exception('"' + name + '" not defined in ' + obj, {
loc: loc,
});
Expand Down
19 changes: 19 additions & 0 deletions spec/strict.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,25 @@ describe('strict', function () {
.toCompileTo('');
});

it('should handle array length', function () {
expectTemplate('{{hello.length}}')
.withCompileOptions({ strict: true })
.withInput({ hello: [1, 2, 3] })
.toCompileTo('3');
});

it('should handle string length', function () {
expectTemplate('{{hello.length}}')
.withCompileOptions({ strict: true })
.withInput({ hello: 'world' })
.toCompileTo('5');

expectTemplate('{{hello.length}}')
.withCompileOptions({ strict: true })
.withInput({ hello: '' })
.toCompileTo('0');
});

it('should error on missing property lookup in known helpers mode', function () {
expectTemplate('{{hello}}')
.withCompileOptions({
Expand Down
Loading