From 1bb35c36df9e5504d092adb88b2475673c9954e5 Mon Sep 17 00:00:00 2001 From: Martin Krizek Date: Tue, 9 Aug 2022 10:12:27 +0200 Subject: [PATCH] Use correct concat function for blocks evaluation Fixes #1701 --- CHANGES.rst | 2 ++ src/jinja2/runtime.py | 4 ++-- tests/test_nativetypes.py | 9 +++++++++ 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/CHANGES.rst b/CHANGES.rst index 7ee75a6a7..6316cb637 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -5,6 +5,8 @@ Version 3.2.0 Unreleased +- Use correct concat function for blocks evaluation. :issue:`1701` + Version 3.1.2 ------------- diff --git a/src/jinja2/runtime.py b/src/jinja2/runtime.py index 985842b28..7496c7646 100644 --- a/src/jinja2/runtime.py +++ b/src/jinja2/runtime.py @@ -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 ) @@ -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) diff --git a/tests/test_nativetypes.py b/tests/test_nativetypes.py index 8c8525251..f78bf9131 100644 --- a/tests/test_nativetypes.py +++ b/tests/test_nativetypes.py @@ -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)