Skip to content
This repository has been archived by the owner on Apr 11, 2018. It is now read-only.

Commit

Permalink
Merge pull request #471 from finnsoft/master
Browse files Browse the repository at this point in the history
Fixed: don't throw errors on accessing property of null object
  • Loading branch information
paularmstrong committed Jun 27, 2014
2 parents 9b75436 + 0eaf9b8 commit 8475519
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -399,12 +399,12 @@ TokenParser.prototype = {
m = match,
build = '';

build = '(typeof ' + c + ' !== "undefined"';
build = '(typeof ' + c + ' !== "undefined" && ' + c + ' !== null';
utils.each(m, function (v, i) {
if (i === 0) {
return;
}
build += ' && ' + c + '.' + v + ' !== undefined';
build += ' && ' + c + '.' + v + ' !== undefined && ' + c + '.' + v + ' !== null';
c += '.' + v;
});
build += ')';
Expand Down
7 changes: 7 additions & 0 deletions tests/basic.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,13 @@ describe('options', function () {
.to.throwError();
});
});

describe('null object', function () {
it('can skip null object', function () {
expect(swig.render('{{ a.property }}', { locals: { a: null }})).to.equal('');
});
});

});

describe('separate instances', function () {
Expand Down

0 comments on commit 8475519

Please sign in to comment.