Skip to content

Commit

Permalink
Merge branch '2.9-maintenance'
Browse files Browse the repository at this point in the history
  • Loading branch information
mitsuhiko committed Jan 24, 2017
2 parents 0fcf451 + ca124c5 commit d927c88
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 0 deletions.
3 changes: 3 additions & 0 deletions CHANGES
Expand Up @@ -20,6 +20,9 @@ Version 2.9.5
- Added back support for custom contexts that override the old `resolve`
method since it was hard for people to spot that this could cause a
regression.
- Correctly use the buffer for the else block of for loops. This caused
invalid syntax errors to be caused on 2.x and completely wrong behavior
on Python 3 (#669)

Version 2.9.4
-------------
Expand Down
3 changes: 3 additions & 0 deletions jinja2/compiler.py
Expand Up @@ -1070,6 +1070,9 @@ def visit_For(self, node, frame):
self.indent()
self.buffer(loop_frame)

# Use the same buffer for the else frame
else_frame.buffer = loop_frame.buffer

# make sure the loop variable is a special one and raise a template
# assertion error if a loop tries to write to loop
if extended_loop:
Expand Down
6 changes: 6 additions & 0 deletions tests/test_regression.py
Expand Up @@ -520,3 +520,9 @@ def resolve(self, name):
assert x.resolve_or_missing('foo') == 42
assert x.resolve_or_missing('bar') == 23
assert x.resolve_or_missing('baz') is missing

def test_recursive_loop_bug(self, env):
tmpl = env.from_string('''
{%- for value in values recursive %}1{% else %}0{% endfor -%}
''')
assert tmpl.render(values=[]) == '0'

0 comments on commit d927c88

Please sign in to comment.