diff options
Diffstat (limited to 'jinja2')
-rw-r--r-- | jinja2/filters.py | 2 | ||||
-rw-r--r-- | jinja2/testsuite/api.py | 1 |
2 files changed, 2 insertions, 1 deletions
diff --git a/jinja2/filters.py b/jinja2/filters.py index c1dee42..9dd693d 100644 --- a/jinja2/filters.py +++ b/jinja2/filters.py @@ -278,7 +278,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 diff --git a/jinja2/testsuite/api.py b/jinja2/testsuite/api.py index 4f6a1d0..f6bca48 100644 --- a/jinja2/testsuite/api.py +++ b/jinja2/testsuite/api.py @@ -229,6 +229,7 @@ class UndefinedTestCase(JinjaTestCase): 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 }}") |