Fixed #9756: the for tag no longer leaves the context stack unbalanced when dealing with an empty iterable. Thanks, seanl.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@10439 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
4f7950ac05
commit
6d6bbb6d05
|
@ -125,6 +125,7 @@ class ForNode(Node):
|
||||||
values = list(values)
|
values = list(values)
|
||||||
len_values = len(values)
|
len_values = len(values)
|
||||||
if len_values < 1:
|
if len_values < 1:
|
||||||
|
context.pop()
|
||||||
return self.nodelist_empty.render(context)
|
return self.nodelist_empty.render(context)
|
||||||
nodelist = NodeList()
|
nodelist = NodeList()
|
||||||
if self.is_reversed:
|
if self.is_reversed:
|
||||||
|
|
|
@ -70,6 +70,9 @@ class SomeException(Exception):
|
||||||
class SomeOtherException(Exception):
|
class SomeOtherException(Exception):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
class ContextStackException(Exception):
|
||||||
|
pass
|
||||||
|
|
||||||
class SomeClass:
|
class SomeClass:
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.otherclass = OtherClass()
|
self.otherclass = OtherClass()
|
||||||
|
@ -231,6 +234,9 @@ class Templates(unittest.TestCase):
|
||||||
try:
|
try:
|
||||||
test_template = loader.get_template(name)
|
test_template = loader.get_template(name)
|
||||||
output = self.render(test_template, vals)
|
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:
|
except Exception:
|
||||||
exc_type, exc_value, exc_tb = sys.exc_info()
|
exc_type, exc_value, exc_tb = sys.exc_info()
|
||||||
if exc_type != result:
|
if exc_type != result:
|
||||||
|
@ -256,7 +262,12 @@ class Templates(unittest.TestCase):
|
||||||
('-'*70, ("\n%s\n" % ('-'*70)).join(failures)))
|
('-'*70, ("\n%s\n" % ('-'*70)).join(failures)))
|
||||||
|
|
||||||
def render(self, test_template, vals):
|
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):
|
def get_template_tests(self):
|
||||||
# SYNTAX --
|
# SYNTAX --
|
||||||
|
|
Loading…
Reference in New Issue