]> git.ipfire.org Git - thirdparty/jinja.git/commitdiff
Allow to pass a list to native_concat
authorMartin Krizek <martin.krizek@gmail.com>
Wed, 17 Jan 2018 20:38:58 +0000 (21:38 +0100)
committerMartin Krizek <martin.krizek@gmail.com>
Wed, 17 Jan 2018 20:38:58 +0000 (21:38 +0100)
jinja2/nativetypes.py
tests/test_nativetypes.py

index fe17e4138df3f1c1d3cf8d207135c847f5d66615..fcfeddfe501bf376aa5c87162ca12398d9a6c209 100644 (file)
@@ -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)
index aec1a3b8fff789c2cf8085d86fa8bff6f8502909..769bbc0a584af3aaf43d77f47bf84ee9dbb27780 100644 (file)
@@ -108,3 +108,9 @@ class TestNativeEnvironment(object):
         result = t.render()
         assert not isinstance(result, type)
         assert result in ["<type 'bool'>", "<class 'bool'>"]
+
+    def test_string(self, env):
+        t = env.from_string("[{{ 'all' }}]")
+        result = t.render()
+        assert isinstance(result, text_type)
+        assert result == "[all]"