use env.concat when calling block reference

This commit is contained in:
Martin Krizek 2022-08-09 10:12:27 +02:00 committed by David Lord
parent 791dd3b041
commit d3a0b1a4ab
No known key found for this signature in database
GPG Key ID: 43368A7AA8CC5926
3 changed files with 16 additions and 2 deletions

View 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

View 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)

View 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)