Skip to content

Commit

Permalink
Use correct concat function for blocks evaluation
Browse files Browse the repository at this point in the history
  • Loading branch information
mkrizek committed Aug 9, 2022
1 parent 997f7f5 commit e644b20
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 @@ -5,6 +5,8 @@ Version 3.2.0

Unreleased

- Use correct concat function for blocks evaluation. :issue:`1701`


Version 3.1.2
-------------
Expand Down
6 changes: 4 additions & 2 deletions src/jinja2/runtime.py
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,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 @@ -376,7 +376,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 e644b20

Please # to comment.