Skip to content

Commit

Permalink
Use correct concat function for blocks evaluation (#1702)
Browse files Browse the repository at this point in the history
  • Loading branch information
davidism authored Dec 19, 2024
2 parents 791dd3b + d3a0b1a commit a4abbfd
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
2 changes: 2 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 4 additions & 2 deletions src/jinja2/runtime.py
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ def super(self) -> t.Union["BlockReference", "Undefined"]:

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

Expand All @@ -381,7 +381,9 @@ def __call__(self) -> str:
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)
Expand Down
10 changes: 10 additions & 0 deletions tests/test_nativetypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

0 comments on commit a4abbfd

Please sign in to comment.