Author: jacob
Date: 2009-04-07 17:02:34 -0500 (Tue, 07 Apr 2009)
New Revision: 10439
Modified:
django/trunk/django/template/defaulttags.py
django/trunk/tests/regressiontests/templates/tests.py
Log:
Fixed #9756: the for tag no longer leaves the context stack unbalanced when
dealing with an empty iterable. Thanks, seanl.
Modified: django/trunk/django/template/defaulttags.py
===================================================================
--- django/trunk/django/template/defaulttags.py 2009-04-07 21:55:39 UTC (rev
10438)
+++ django/trunk/django/template/defaulttags.py 2009-04-07 22:02:34 UTC (rev
10439)
@@ -125,6 +125,7 @@
values = list(values)
len_values = len(values)
if len_values < 1:
+ context.pop()
return self.nodelist_empty.render(context)
nodelist = NodeList()
if self.is_reversed:
Modified: django/trunk/tests/regressiontests/templates/tests.py
===================================================================
--- django/trunk/tests/regressiontests/templates/tests.py 2009-04-07
21:55:39 UTC (rev 10438)
+++ django/trunk/tests/regressiontests/templates/tests.py 2009-04-07
22:02:34 UTC (rev 10439)
@@ -69,6 +69,9 @@
class SomeOtherException(Exception):
pass
+
+class ContextStackException(Exception):
+ pass
class SomeClass:
def __init__(self):
@@ -231,6 +234,9 @@
try:
test_template = loader.get_template(name)
output = self.render(test_template, vals)
+ except ContextStackException:
+ failures.append("Template test
(TEMPLATE_STRING_IF_INVALID='%s'): %s -- FAILED. Context stack was left
imbalanced" % (invalid_str, name))
+ continue
except Exception:
exc_type, exc_value, exc_tb = sys.exc_info()
if exc_type != result:
@@ -256,7 +262,12 @@
('-'*70, ("\n%s\n" % ('-'*70)).join(failures)))
def render(self, test_template, vals):
- return test_template.render(template.Context(vals[1]))
+ context = template.Context(vals[1])
+ before_stack_size = len(context.dicts)
+ output = test_template.render(context)
+ if len(context.dicts) != before_stack_size:
+ raise ContextStackException
+ return output
def get_template_tests(self):
# SYNTAX --
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/django-updates?hl=en
-~----------~----~----~----~------~----~------~--~---