Fixed a translation error caused by looping over empty recursive loops.
--HG--
branch : trunk
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 @@
"""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 @@
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 @@
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=[])) == ''