Author: russellm Date: 2010-04-12 08:56:38 -0500 (Mon, 12 Apr 2010) New Revision: 12954
Modified: django/trunk/django/template/defaulttags.py django/trunk/tests/regressiontests/templates/tests.py Log: 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. Modified: django/trunk/django/template/defaulttags.py =================================================================== --- django/trunk/django/template/defaulttags.py 2010-04-12 13:28:46 UTC (rev 12953) +++ django/trunk/django/template/defaulttags.py 2010-04-12 13:56:38 UTC (rev 12954) @@ -243,7 +243,12 @@ yield node 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) else: return self.nodelist_false.render(context) Modified: django/trunk/tests/regressiontests/templates/tests.py =================================================================== --- django/trunk/tests/regressiontests/templates/tests.py 2010-04-12 13:28:46 UTC (rev 12953) +++ django/trunk/tests/regressiontests/templates/tests.py 2010-04-12 13:56:38 UTC (rev 12954) @@ -782,6 +782,12 @@ 'if-tag-error11': ("{% if 1 == %}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 ### IFCHANGED TAG ######################################################### -- You received this message because you are subscribed to the Google Groups "Django updates" group. To post to this group, send email to django-upda...@googlegroups.com. To unsubscribe from this group, send email to django-updates+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-updates?hl=en.