]> git.ipfire.org Git - thirdparty/jinja.git/commitdiff
native_concat: pass only strings to literal_eval 1339/head
authorMartin Krizek <martin.krizek@gmail.com>
Thu, 28 Jan 2021 09:08:50 +0000 (10:08 +0100)
committerMartin Krizek <martin.krizek@gmail.com>
Thu, 28 Jan 2021 11:13:30 +0000 (12:13 +0100)
If there is only single node and it is not a string, there is no point
in passing it into ``literal_eval``, just return it immediately.

One of the examples where passing a non-string node into
``literal_eval`` would actually cause problems is when the node is
``Undefined``. On Python 3.10 this would cause ``UndefinedError``
instead of just ``Undefined`` being returned.

Fixes #1335

CHANGES.rst
src/jinja2/nativetypes.py

index 6f4649fd3c65e2aa8ceebd5047f92eabca843b20..43e4ad6acc528342f9479bd27fcfe2cd9ee045ae 100644 (file)
@@ -16,6 +16,9 @@ Unreleased
 -   Add ability to ignore ``trim_blocks`` using ``+%}``. :issue:`1036`
 -   Fix a bug that caused custom async-only filters to fail with
     constant input. :issue:`1279`
+-   Fix UndefinedError incorrectly being thrown on an undefined variable
+    instead of ``Undefined`` being returned on
+    ``NativeEnvironment`` on Python 3.10. :issue:`1335`
 
 
 Version 2.11.2
index c71e033641b6f0523f4c2480396569dc8cddcea0..3ac70cf71e28f0e3f9727abba2a121274c12423c 100644 (file)
@@ -26,6 +26,8 @@ def native_concat(nodes):
 
     if len(head) == 1:
         raw = head[0]
+        if not isinstance(raw, str):
+            return raw
     else:
         raw = "".join([str(v) for v in chain(head, nodes)])