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 1bb35c3
Show file tree
Hide file tree
Showing 3 changed files with 13 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
4 changes: 2 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,7 @@ 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(self._stack[self._depth](self._context)) # type: ignore

if self._context.eval_ctx.autoescape:
return Markup(rv)
Expand Down
9 changes: 9 additions & 0 deletions tests/test_nativetypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,3 +160,12 @@ 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 1bb35c3

Please # to comment.