Refs #13167 -- Corrected a regression in the way non-existent variables are handled by {% if %} tags. Thanks to ohmi2 for pointing out the regression in 1.2, and Karen for the patch.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@12954 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
55c31fbdef
commit
2cebe4395e
|
@ -243,7 +243,12 @@ class IfNode(Node):
|
||||||
yield node
|
yield node
|
||||||
|
|
||||||
def render(self, context):
|
def render(self, context):
|
||||||
if self.var.eval(context):
|
try:
|
||||||
|
var = self.var.eval(context)
|
||||||
|
except VariableDoesNotExist:
|
||||||
|
var = None
|
||||||
|
|
||||||
|
if var:
|
||||||
return self.nodelist_true.render(context)
|
return self.nodelist_true.render(context)
|
||||||
else:
|
else:
|
||||||
return self.nodelist_false.render(context)
|
return self.nodelist_false.render(context)
|
||||||
|
|
|
@ -782,6 +782,12 @@ class Templates(unittest.TestCase):
|
||||||
'if-tag-error11': ("{% if 1 == %}yes{% endif %}", {}, template.TemplateSyntaxError),
|
'if-tag-error11': ("{% if 1 == %}yes{% endif %}", {}, template.TemplateSyntaxError),
|
||||||
'if-tag-error12': ("{% if a not b %}yes{% endif %}", {}, template.TemplateSyntaxError),
|
'if-tag-error12': ("{% if a not b %}yes{% endif %}", {}, template.TemplateSyntaxError),
|
||||||
|
|
||||||
|
# Non-existent args
|
||||||
|
'if-tag-badarg01':("{% if x|default_if_none:y %}yes{% endif %}", {}, ''),
|
||||||
|
'if-tag-badarg02':("{% if x|default_if_none:y %}yes{% endif %}", {'y': 0}, ''),
|
||||||
|
'if-tag-badarg03':("{% if x|default_if_none:y %}yes{% endif %}", {'y': 1}, 'yes'),
|
||||||
|
'if-tag-badarg04':("{% if x|default_if_none:y %}yes{% else %}no{% endif %}", {}, 'no'),
|
||||||
|
|
||||||
# Additional, more precise parsing tests are in SmartIfTests
|
# Additional, more precise parsing tests are in SmartIfTests
|
||||||
|
|
||||||
### IFCHANGED TAG #########################################################
|
### IFCHANGED TAG #########################################################
|
||||||
|
|
Loading…
Reference in New Issue