Ticket #9756: for-tag-leaves-imbalanced-context-stack.patch
File for-tag-leaves-imbalanced-context-stack.patch, 1.9 KB (added by , 16 years ago) |
---|
-
django/template/defaulttags.py
128 128 values = list(values) 129 129 len_values = len(values) 130 130 if len_values < 1: 131 context.pop() 131 132 return self.nodelist_empty.render(context) 132 133 nodelist = NodeList() 133 134 if self.is_reversed: -
tests/regressiontests/templates/tests.py
63 63 64 64 class SomeOtherException(Exception): 65 65 pass 66 67 class ContextStackException(Exception): 68 pass 66 69 67 70 class SomeClass: 68 71 def __init__(self): … … 203 206 try: 204 207 test_template = loader.get_template(name) 205 208 output = self.render(test_template, vals) 209 except ContextStackException: 210 failures.append("Template test (TEMPLATE_STRING_IF_INVALID='%s'): %s -- FAILED. Context stack was left imbalanced" % (invalid_str, name)) 211 continue 206 212 except Exception, e: 207 213 if e.__class__ != result: 208 214 raise … … 226 232 self.assertEqual(failures, [], '\n'.join(failures)) 227 233 228 234 def render(self, test_template, vals): 229 return test_template.render(template.Context(vals[1])) 235 context = template.Context(vals[1]) 236 before_stack_size = len(context.dicts) 237 output = test_template.render(context) 238 if len(context.dicts) != before_stack_size: 239 raise ContextStackException 240 return output 230 241 231 242 def get_template_tests(self): 232 243 # SYNTAX --