Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixed #9756: the for tag no longer leaves the context stack unbalance…

…d when dealing with an empty iterable. Thanks, seanl.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@10439 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 6d6bbb6d0571d32b10978dc36a905c8d48c3ce1c 1 parent 4f7950a
Jacob Kaplan-Moss authored April 07, 2009
1  django/template/defaulttags.py
@@ -125,6 +125,7 @@ def render(self, context):
125 125
             values = list(values)
126 126
         len_values = len(values)
127 127
         if len_values < 1:
  128
+            context.pop()
128 129
             return self.nodelist_empty.render(context)
129 130
         nodelist = NodeList()
130 131
         if self.is_reversed:
13  tests/regressiontests/templates/tests.py
@@ -69,6 +69,9 @@ class SomeException(Exception):
69 69
 
70 70
 class SomeOtherException(Exception):
71 71
     pass
  72
+    
  73
+class ContextStackException(Exception):
  74
+    pass
72 75
 
73 76
 class SomeClass:
74 77
     def __init__(self):
@@ -231,6 +234,9 @@ def test_template_loader(template_name, template_dirs=None):
231 234
                 try:
232 235
                     test_template = loader.get_template(name)
233 236
                     output = self.render(test_template, vals)
  237
+                except ContextStackException:
  238
+                    failures.append("Template test (TEMPLATE_STRING_IF_INVALID='%s'): %s -- FAILED. Context stack was left imbalanced" % (invalid_str, name))
  239
+                    continue
234 240
                 except Exception:
235 241
                     exc_type, exc_value, exc_tb = sys.exc_info()
236 242
                     if exc_type != result:
@@ -256,7 +262,12 @@ def test_template_loader(template_name, template_dirs=None):
256 262
             ('-'*70, ("\n%s\n" % ('-'*70)).join(failures)))
257 263
 
258 264
     def render(self, test_template, vals):
259  
-        return test_template.render(template.Context(vals[1]))
  265
+        context = template.Context(vals[1])
  266
+        before_stack_size = len(context.dicts)
  267
+        output = test_template.render(context)
  268
+        if len(context.dicts) != before_stack_size:
  269
+            raise ContextStackException
  270
+        return output
260 271
 
261 272
     def get_template_tests(self):
262 273
         # SYNTAX --

0 notes on commit 6d6bbb6

Please sign in to comment.
Something went wrong with that request. Please try again.