From 9ef99dcd82c153ee503aaea2feea61b184e7f44e Mon Sep 17 00:00:00 2001 From: Martin Krizek Date: Wed, 17 Jan 2018 21:38:58 +0100 Subject: [PATCH] Allow to pass a list to native_concat --- jinja2/nativetypes.py | 6 +++++- tests/test_nativetypes.py | 6 ++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/jinja2/nativetypes.py b/jinja2/nativetypes.py index fe17e413..fcfeddfe 100644 --- a/jinja2/nativetypes.py +++ b/jinja2/nativetypes.py @@ -1,4 +1,5 @@ import sys +import types from ast import literal_eval from itertools import islice, chain from jinja2 import nodes @@ -20,10 +21,13 @@ def native_concat(nodes): if not head: return None + if isinstance(nodes, types.GeneratorType): + nodes = chain(head, nodes) + if len(head) == 1: out = head[0] else: - out = u''.join([text_type(v) for v in chain(head, nodes)]) + out = u''.join([text_type(v) for v in nodes]) try: return literal_eval(out) diff --git a/tests/test_nativetypes.py b/tests/test_nativetypes.py index aec1a3b8..769bbc0a 100644 --- a/tests/test_nativetypes.py +++ b/tests/test_nativetypes.py @@ -108,3 +108,9 @@ class TestNativeEnvironment(object): result = t.render() assert not isinstance(result, type) assert result in ["", ""] + + def test_string(self, env): + t = env.from_string("[{{ 'all' }}]") + result = t.render() + assert isinstance(result, text_type) + assert result == "[all]" -- 2.47.2