Skip to content

Commit

Permalink
Merge pull request #248 from garygreen/fix/length-undefined
Browse files Browse the repository at this point in the history
Fix undefined variables throwing exception with length filter
  • Loading branch information
jlongster committed Aug 15, 2014
2 parents 99c4b78 + 17d5735 commit 3c25b95
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/filters.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ var filters = {
},

length: function(arr) {
return arr.length;
return arr !== undefined ? arr.length : 0;
},

list: function(val) {
Expand Down
5 changes: 5 additions & 0 deletions tests/filters.js
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,11 @@
finish(done);
});

it('length handle undefined variables', function(done) {
equal('{{ blah|length }}', '0');
finish(done);
});

it('list', function(done) {
equal('{% for i in "foobar" | list %}{{ i }},{% endfor %}',
'f,o,o,b,a,r,');
Expand Down

0 comments on commit 3c25b95

Please sign in to comment.