Permalink
Browse files

Fixing `default` filter for undefined variables.

closes gh-18
  • Loading branch information...
paularmstrong committed Oct 1, 2011
1 parent abf0c34 commit ff14c668a85762fd235d54a7091614e70777c514
Showing with 7 additions and 1 deletion.
  1. +6 −0 lib/helpers.js
  2. +1 −1 tests/filters.test.js
View
@@ -196,5 +196,11 @@ exports.setVar = function (varName, argument) {
' ' + varName + ' = ' + exports.wrapFilters(exports.escape(argument.name), argument.filters, '__context', argument.escape) + ';' +
'}';
+ if (argument.filters.length) {
+ out += ' else if (true) {';
+ out += ' ' + varName + ' = ' + exports.wrapFilters('', argument.filters, null, argument.escape) + ';';
+ out += '}';
+ }
+
return out;
};
View
@@ -85,7 +85,7 @@ exports.default = function (test) {
testFilter(test, 'default("blah")', { v: 'foo' }, 'foo', 'string not overridden by default');
testFilter(test, 'default("blah")', { v: 0 }, '0', 'zero not overridden by default');
testFilter(test, 'default("blah")', { v: '' }, 'blah', 'empty string overridden by default');
- // testFilter(test, 'default("blah")', {}, 'blah', 'default overrides undefined');
+ testFilter(test, 'default("blah")', {}, 'blah', 'default overrides undefined');
testFilter(test, 'default("blah")', { v: null }, 'blah', 'default overrides null');
testFilter(test, 'default("blah")', { v: false }, 'blah', 'default overrides false');
test.done();

0 comments on commit ff14c66

Please sign in to comment.