Skip to content
Myr

fixed an operator precedence error introduced in 2.5.2.

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Statements like "-foo.bar" had their implicit parentheses applied around the first part of the expression ("(-foo).bar") instead of the more correct "-(foo.bar)".

authored by Armin Ronacher · committed by Armin Ronacher · parent 9dc0619 · Browse files · 3 files+33 added−4 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

3 files+33 added−4 removed

  • other:+33 added−4 removed

3 files+33 added−4 removed

modified:jinja2/testsuite/lexnparse.py+6 added
373 unmodified lines
374{% for item in [1, 2] %}{% set foo = 1 %}{% endfor %}\375{{ foo }}''')376 assert tmpl.render() == '0'377378 def test_parse_unary(self):379 tmpl = env.from_string('{{ -foo["bar"] }}')380 assert tmpl.render(foo={'bar': 42}) == '-42'381 tmpl = env.from_string('{{ -foo["bar"]|abs }}')382 assert tmpl.render(foo={'bar': 42}) == '42'383384385def suite():386 suite = unittest.TestSuite()387 suite.addTest(unittest.makeSuite(LexerTestCase))388 suite.addTest(unittest.makeSuite(ParserTestCase))
2 unmodified lines
modified:jinja2/parser.py+18 added-4 removed
523 unmodified lines
524 left = nodes.Pow(left, right, lineno=lineno)525 lineno = self.stream.current.lineno526 return left527528 def parse_unary(self, with_postfix=True):528 def parse_unary(self, with_filter=True):529 token_type = self.stream.current.type530 lineno = self.stream.current.lineno531 if token_type == 'sub':532 next(self.stream)
2 unmodified lines
535 next(self.stream)536 node = nodes.Pos(self.parse_unary(False), lineno=lineno)537 else:538 node = self.parse_primary()539 node = self.parse_postfix(node)539 if with_postfix:540 node = self.parse_postfix(node)540 if with_filter:541 node = self.parse_filter_expr(node)542 return node543544 def parse_primary(self):545 token = self.stream.current
115 unmodified lines
661 while 1:662 token_type = self.stream.current.type663 if token_type == 'dot' or token_type == 'lbracket':664 node = self.parse_subscript(node)665 # calls are valid both after postfix expressions (getattr666 # and getitem) as well as filters and tests667 elif token_type == 'lparen':668 node = self.parse_call(node)669 else:670 break671 return node672673 def parse_filter_expr(self, node):674 while 1:675 token_type = self.stream.current.type666 elif token_type == 'pipe':676 if token_type == 'pipe':677 node = self.parse_filter(node)678 elif token_type == 'name' and self.stream.current.value == 'is':679 node = self.parse_test(node)680 # calls are valid both after postfix expressions (getattr681 # and getitem) as well as filters and tests682 elif token_type == 'lparen':683 node = self.parse_call(node)684 else:685 break686 return node687
209 unmodified lines
modified:CHANGES+9 added
1Jinja2 Changelog2================34Version 2.5.35-------------6(bugfix release, release date to be announced)78- fixed an operator precedence error introduced in 2.5.2. Statements9 like "-foo.bar" had their implicit parentheses applied around the10 first part of the expression ("(-foo).bar") instead of the more11 correct "-(foo.bar)".1213Version 2.5.214-------------15(bugfix release, released on August 18th 2010)16
204 unmodified lines