]> git.ipfire.org Git - thirdparty/jinja.git/commitdiff
Fix blank iterables not parsing correctly
authorKevin Brown <kevin@kevin-brown.com>
Thu, 14 May 2020 15:43:05 +0000 (11:43 -0400)
committerKevin Brown <kevin@kevin-brown.com>
Thu, 14 May 2020 15:43:05 +0000 (11:43 -0400)
The AST returns `None` instead of an empty array of the value of an
empty iterable literal, so we need to special case when that happens
to get them to parse consistently.

src/jinja2/new_parser.py

index 5503d1e2ab99baaf21bbd7df053973541c91cbb7..37bcf77c0cc717aec8725de94ac6c296af41d8d6 100644 (file)
@@ -619,6 +619,10 @@ def parse_literal(ast):
             lineno=lineno_from_parseinfo(ast['parseinfo'])\r
         )\r
     elif literal_type == 'dictionary':\r
+        if not ast['value']:\r
+            ast['value'] = []\r
+\r
+\r
         items = [\r
             nodes.Pair(\r
                 parse_literal(item['key']),\r
@@ -638,6 +642,9 @@ def parse_literal(ast):
             lineno=lineno_from_parseinfo(ast['parseinfo'])\r
         )\r
     elif literal_type == 'list':\r
+        if not ast['value']:\r
+            ast['value'] = []\r
+\r
         items = [\r
             parse_literal(item) for item in ast['value']\r
         ]\r
@@ -647,6 +654,9 @@ def parse_literal(ast):
             lineno=lineno_from_parseinfo(ast['parseinfo'])\r
         )\r
     elif literal_type == 'tuple':\r
+        if not ast['value']:\r
+            ast['value'] = []\r
+\r
         items = [\r
             parse_literal(item) for item in ast['value']\r
         ]\r