diff options
author | Martin Krizek <martin.krizek@gmail.com> | 2021-01-28 10:08:50 +0100 |
---|---|---|
committer | Martin Krizek <martin.krizek@gmail.com> | 2021-01-28 12:13:30 +0100 |
commit | bd8bad37d1c0e2d8995a44fd88e234f5340afec5 (patch) | |
tree | c58a757d55198bc257a364e3715afc1460c4398e /src | |
parent | 8d69d20c1d5c7af725417ca588e9c1191d9957bc (diff) | |
download | jinja2-bd8bad37d1c0e2d8995a44fd88e234f5340afec5.tar.gz |
native_concat: pass only strings to literal_eval
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
Diffstat (limited to 'src')
-rw-r--r-- | src/jinja2/nativetypes.py | 2 |
1 files changed, 2 insertions, 0 deletions
diff --git a/src/jinja2/nativetypes.py b/src/jinja2/nativetypes.py index c71e033..3ac70cf 100644 --- a/src/jinja2/nativetypes.py +++ b/src/jinja2/nativetypes.py @@ -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)]) |