Fixed a translation error caused by looping over empty recursive loops.
authorArmin Ronacher <armin.ronacher@active-4.com>
Thu, 25 Dec 2008 17:33:46 +0000 (18:33 +0100)
committerArmin Ronacher <armin.ronacher@active-4.com>
Thu, 25 Dec 2008 17:33:46 +0000 (18:33 +0100)
--HG--
branch : trunk

CHANGES
jinja2/compiler.py
tests/test_forloop.py

diff --git a/CHANGES b/CHANGES
index 38703587fba6a0703b7a5b8baf40d61943a293ae..a70061b1b9ebd53f8f9db92973c0ca79ea357a2f 100644 (file)
--- 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
 -----------
index 5074a342ecbd11dd492636762ea1ac3117b7856f..54a80baaa2b5cc207008fe55be219087d82acf1b 100644 (file)
@@ -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
index 0c307ecbc6662c200583ecbfedd4e5d3945babdb..f5e4996ea4d396d374095a9a04d0aaa875322ec2 100644 (file)
@@ -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=[])) == ''