Permalink
Browse files

Prevent default filter from throwing UndefinedError when boolean flag…

… is used with StrictUndefined.
  • Loading branch information...
1 parent 6327f79 commit dd7fa4aeaa5be49044c2f932c47e0daba5318666 @gazpachoking committed Jul 5, 2012
Showing with 2 additions and 1 deletion.
  1. +1 −1 jinja2/filters.py
  2. +1 −0 jinja2/testsuite/api.py
View
2 jinja2/filters.py
@@ -276,7 +276,7 @@ def do_default(value, default_value=u'', boolean=False):
{{ ''|default('the string was empty', true) }}
"""
- if (boolean and not value) or isinstance(value, Undefined):
+ if isinstance(value, Undefined) or (boolean and not value):
return default_value
return value
View
1 jinja2/testsuite/api.py
@@ -214,6 +214,7 @@ def test_strict_undefined(self):
self.assert_equal(env.from_string('{{ missing is not defined }}').render(), 'True')
self.assert_raises(UndefinedError, env.from_string('{{ foo.missing }}').render, foo=42)
self.assert_raises(UndefinedError, env.from_string('{{ not missing }}').render)
+ self.assert_equal(env.from_string('{{ missing|default("default", true) }}').render(), 'default')
def test_indexing_gives_undefined(self):
t = Template("{{ var[42].foo }}")

0 comments on commit dd7fa4a

Please sign in to comment.