From cebd838f5af4ff99d862cbafab1a6a782dd50b56 Mon Sep 17 00:00:00 2001 From: Armin Ronacher Date: Thu, 25 Dec 2008 18:33:46 +0100 Subject: [PATCH] Fixed a translation error caused by looping over empty recursive loops. --HG-- branch : trunk --- CHANGES | 8 +++++--- jinja2/compiler.py | 5 +++-- tests/test_forloop.py | 7 +++++++ 3 files changed, 15 insertions(+), 5 deletions(-) diff --git a/CHANGES b/CHANGES index 3870358..a70061b 100644 --- a/CHANGES +++ b/CHANGES @@ -1,9 +1,11 @@ Jinja2 Changelog ================ -Version 2.2 ------------ -(codename to be selected, release date yet unknown) +Version 2.1.1 +------------- +(Bugfix release) + +- Fixed a translation error caused by looping over empty recursive loops. Version 2.1 ----------- diff --git a/jinja2/compiler.py b/jinja2/compiler.py index 5074a34..54a80ba 100644 --- a/jinja2/compiler.py +++ b/jinja2/compiler.py @@ -656,7 +656,7 @@ class CodeGenerator(NodeVisitor): """Return a human readable position for the node.""" rv = 'line %d' % node.lineno if self.name is not None: - rv += ' in' + repr(self.name) + rv += ' in ' + repr(self.name) return rv # -- Statement Visitors @@ -1012,7 +1012,8 @@ class CodeGenerator(NodeVisitor): self.outdent() # reset the aliases if there are any. - self.pop_scope(aliases, loop_frame) + if not node.recursive: + self.pop_scope(aliases, loop_frame) # if the node was recursive we have to return the buffer contents # and start the iteration code diff --git a/tests/test_forloop.py b/tests/test_forloop.py index 0c307ec..f5e4996 100644 --- a/tests/test_forloop.py +++ b/tests/test_forloop.py @@ -153,3 +153,10 @@ def test_scoped_loop_var(env): t = env.from_string('{% for x in seq %}{% for y in seq %}' '{{ loop.first }}{% endfor %}{% endfor %}') assert t.render(seq='ab') == 'TrueFalseTrueFalse' + + +def test_recursive_empty_loop_iter(env): + t = env.from_string(''' + {%- for item in foo recursive -%}{%- endfor -%} + ''') + assert t.render(dict(foo=[])) == '' -- 2.26.2