From: Kevin Date: Thu, 14 May 2020 14:00:09 +0000 (-0400) Subject: Tuples must contain a comma X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=7a34fa03b4e065f9237645eef34192772e63992b;p=thirdparty%2Fjinja.git Tuples must contain a comma This fixes an issue where parentheses-wrapped variables were being interpreted by the grammar as tuples. This was because we were lacking a definiiton for variable wrapped in parentheses and because the grammar wasn't enforcing multiple values to be present in tuples. --- diff --git a/grammar.ebnf b/grammar.ebnf index ec2d1557..3c034ef1 100644 --- a/grammar.ebnf +++ b/grammar.ebnf @@ -156,6 +156,17 @@ variable_close ; variable_identifier + = + | variable_identifier_parentheses + | variable_identifier_raw + ; + +variable_identifier_parentheses + = + "(" @:variable_identifier ")" + ; + +variable_identifier_raw = variable:( LITERAL | IDENTIFIER ) accessors:{ variable_accessor }* @@ -421,7 +432,7 @@ TUPLE_LITERAL = literal_type:`tuple` ( - | ( "(" {SP}* value+:LITERAL {SP}* { "," {SP}* value+:LITERAL {SP}* } ")" ) + | ( "(" {SP}* value+:LITERAL {SP}* { "," {SP}* value+:LITERAL {SP}* }+ ")" ) | ( "(" {SP}* value+:LITERAL {SP}* "," {SP}* ")" ) ) ; diff --git a/src/jinja2/parser.py b/src/jinja2/parser.py index a77d0547..721988cd 100644 --- a/src/jinja2/parser.py +++ b/src/jinja2/parser.py @@ -945,12 +945,10 @@ class Parser: result = parse_template( grammar.parse( - self.source, + self.source.rstrip('\n'), whitespace='', parseinfo=True, semantics=JinjaSemantics(), - trace=True, - colorize=True, ) ) result.set_environment(self.environment)