]> git.ipfire.org Git - thirdparty/jinja.git/commitdiff
allow scoped blocks to access loop vars
authorAmy <leiamy12@gmail.com>
Mon, 22 Jun 2020 19:27:18 +0000 (15:27 -0400)
committerAmy <leiamy12@gmail.com>
Fri, 26 Mar 2021 20:44:36 +0000 (16:44 -0400)
src/jinja2/compiler.py

index df6fa372e60182cbadabd437a538f3c3997d102e..67918cd5ce4416fc9e43e55cb4bdd66c72c0d88f 100644 (file)
@@ -1008,9 +1008,12 @@ class CodeGenerator(NodeVisitor):
 
         # try to figure out if we have an extended loop.  An extended loop
         # is necessary if the loop is in recursive mode if the special loop
-        # variable is accessed in the body.
-        extended_loop = node.recursive or "loop" in find_undeclared(
-            node.iter_child_nodes(only=("body",)), ("loop",)
+        # variable is accessed in the body if the body is a scoped block.
+        extended_loop = (
+            node.recursive
+            or "loop"
+            in find_undeclared(node.iter_child_nodes(only=("body",)), ("loop",))
+            or any(block.scoped for block in node.find_all(nodes.Block))
         )
 
         loop_ref = None