From: Amy Date: Mon, 22 Jun 2020 19:27:18 +0000 (-0400) Subject: allow scoped blocks to access loop vars X-Git-Tag: 3.0.0rc1~28^2~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=fed1b24d5fda4547725c31df3493a6dfdb170884;p=thirdparty%2Fjinja.git allow scoped blocks to access loop vars --- diff --git a/src/jinja2/compiler.py b/src/jinja2/compiler.py index df6fa372..67918cd5 100644 --- a/src/jinja2/compiler.py +++ b/src/jinja2/compiler.py @@ -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