From: Martin Krizek Date: Wed, 17 Jan 2018 20:38:58 +0000 (+0100) Subject: Allow to pass a list to native_concat X-Git-Tag: 2.11.0~128^2~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=9ef99dcd82c153ee503aaea2feea61b184e7f44e;p=thirdparty%2Fjinja.git Allow to pass a list to native_concat --- 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]"