]> git.ipfire.org Git - thirdparty/jinja.git/commitdiff
use env.concat when calling block reference 1702/head
authorMartin Krizek <martin.krizek@gmail.com>
Tue, 9 Aug 2022 08:12:27 +0000 (10:12 +0200)
committerDavid Lord <davidism@gmail.com>
Thu, 19 Dec 2024 15:12:43 +0000 (07:12 -0800)
CHANGES.rst
src/jinja2/runtime.py
tests/test_nativetypes.py

index feb1e6c3db031b94e40b67e638f38325236c570c..540d5cccbe2adb037e09aa4d4afa92920bdce336 100644 (file)
@@ -14,6 +14,8 @@ Unreleased
     ``Template.generate_async``. :pr:`1960`
 -   Avoid leaving async generators unclosed in blocks, includes and extends.
     :pr:`1960`
+-   The runtime uses the correct ``concat`` function for the current environment
+    when calling block references. :issue:`1701`
 
 
 Version 3.1.4
index d10fe9d06e3afdbe21c9670c2a645e7f00e1e94c..c2c7c19379bbb67a47485b95106a337dd15ebd1f 100644 (file)
@@ -367,7 +367,7 @@ class BlockReference:
 
     @internalcode
     async def _async_call(self) -> str:
-        rv = concat(
+        rv = self._context.environment.concat(  # type: ignore
             [x async for x in self._stack[self._depth](self._context)]  # type: ignore
         )
 
@@ -381,7 +381,9 @@ class BlockReference:
         if self._context.environment.is_async:
             return self._async_call()  # type: ignore
 
-        rv = concat(self._stack[self._depth](self._context))
+        rv = self._context.environment.concat(  # type: ignore
+            self._stack[self._depth](self._context)
+        )
 
         if self._context.eval_ctx.autoescape:
             return Markup(rv)
index 8c85252518d390fa752cc75a26842a83b196ca9b..1369081807950ed36239fe2ef2f8e28321cae0f2 100644 (file)
@@ -160,3 +160,13 @@ def test_macro(env):
     result = t.render()
     assert result == 2
     assert isinstance(result, int)
+
+
+def test_block(env):
+    t = env.from_string(
+        "{% block b %}{% for i in range(1) %}{{ loop.index }}{% endfor %}"
+        "{% endblock %}{{ self.b() }}"
+    )
+    result = t.render()
+    assert result == 11
+    assert isinstance(result, int)