From: Kevin Brown Date: Thu, 14 May 2020 15:43:05 +0000 (-0400) Subject: Fix blank iterables not parsing correctly X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=06bcc5f9ac14b9b42d36d5020107d78b5df08315;p=thirdparty%2Fjinja.git Fix blank iterables not parsing correctly 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. --- diff --git a/src/jinja2/new_parser.py b/src/jinja2/new_parser.py index 5503d1e2..37bcf77c 100644 --- a/src/jinja2/new_parser.py +++ b/src/jinja2/new_parser.py @@ -619,6 +619,10 @@ def parse_literal(ast): lineno=lineno_from_parseinfo(ast['parseinfo']) ) elif literal_type == 'dictionary': + if not ast['value']: + ast['value'] = [] + + items = [ nodes.Pair( parse_literal(item['key']), @@ -638,6 +642,9 @@ def parse_literal(ast): lineno=lineno_from_parseinfo(ast['parseinfo']) ) elif literal_type == 'list': + if not ast['value']: + ast['value'] = [] + items = [ parse_literal(item) for item in ast['value'] ] @@ -647,6 +654,9 @@ def parse_literal(ast): lineno=lineno_from_parseinfo(ast['parseinfo']) ) elif literal_type == 'tuple': + if not ast['value']: + ast['value'] = [] + items = [ parse_literal(item) for item in ast['value'] ]