Skip to content
Myr

Correctly use buffer for else frame in loops. Fixes #669

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Armin Ronacher · committed by Armin Ronacher · parent c74de72 · Browse files · 3 files+12 added−0 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

3 files+12 added−0 removed

  • tests:+6 added−0 removed
  • other:+6 added−0 removed

3 files+12 added−0 removed

modified:jinja2/compiler.py+3 added
1038 unmodified lines
1039 self.func('loop'), node)1040 self.indent()1041 self.buffer(loop_frame)10421043 # Use the same buffer for the else frame1044 else_frame.buffer = loop_frame.buffer10451046 # make sure the loop variable is a special one and raise a template1047 # assertion error if a loop tries to write to loop1048 if extended_loop:1049 self.writeline('%s = missing' % loop_ref)
603 unmodified lines
modified:tests/test_regression.py+6 added
518 unmodified lines
519 assert x._legacy_resolve_mode520 assert x.resolve_or_missing('foo') == 42521 assert x.resolve_or_missing('bar') == 23522 assert x.resolve_or_missing('baz') is missing523524 def test_recursive_loop_bug(self, env):525 tmpl = env.from_string('''526 {%- for value in values recursive %}1{% else %}0{% endfor -%}527 ''')528 assert tmpl.render(values=[]) == '0'
modified:CHANGES+3 added
8 unmodified lines
9 caused issues with ansible and it was an unintended change. (#654)10- Added back support for custom contexts that override the old `resolve`11 method since it was hard for people to spot that this could cause a12 regression.13- Correctly use the buffer for the else block of for loops. This caused14 invalid syntax errors to be caused on 2.x and completely wrong behavior15 on Python 3 (#669)1617Version 2.9.418-------------19(bugfix release, released on January 10th 2017)
480 unmodified lines