fixed an issue with unary operators having the wrong precendence.
Before adoption: this commit came in with the history the project adopted, so no landing records it.
--HG-- branch : trunk
authored by Armin Ronacher · committed by Armin Ronacher · parent 2613e5a · Browse files · 3 files·+20 added−13 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+20 added−13 removed
- other:+20 added−13 removed
Provenance
- Commit
2ee64bc- Tree
a5f8598- Author
Armin Ronacher <armin.ronacher@active-4.com>- Committer
Armin Ronacher <armin.ronacher@active-4.com>- Parent
2613e5a
3 files changed+20 added−13 removed
modified:jinja2/testsuite/lexnparse.py+7 added-1 removed
14 unmodified lines15 import unittest16 17 from jinja2.testsuite import JinjaTestCase18 19-from jinja2 import Environment, Template, TemplateSyntaxError, UndefinedError19+from jinja2 import Environment, Template, TemplateSyntaxError, \20+ UndefinedError, nodes21 22 env = Environment()23 24 332 unmodified lines357 tmpl = env.from_string('{{ true }}|{{ false }}|{{ none }}|'358 '{{ none is defined }}|{{ missing is defined }}')359 assert tmpl.render() == 'True|False|None|True|False'360 361+ def test_neg_filter_priority(self):362+ node = env.parse('{{ -1|foo }}')363+ assert isinstance(node.body[0].nodes[0], nodes.Filter)364+ assert isinstance(node.body[0].nodes[0].node, nodes.Neg)365+366 def test_const_assign(self):367 constass1 = '''{% set true = 42 %}'''368 constass2 = '''{% for none in seq %}{% endfor %}'''369 for tmpl in constass1, constass2:15 unmodified linesmodified:jinja2/parser.py+12 added-12 removed
368 unmodified lines369 if with_tuple:370 target = self.parse_tuple(simplified=True,371 extra_end_rules=extra_end_rules)372 else:373- target = self.parse_primary(with_postfix=False)373+ target = self.parse_primary()374 target.set_ctx('store')375 if not target.can_assign():376 self.fail('can\'t assign to %r' % target.__class__.377 __name__.lower(), target.lineno)146 unmodified lines524 left = nodes.Pow(left, right, lineno=lineno)525 lineno = self.stream.current.lineno526 return left527 528- def parse_unary(self):528+ def parse_unary(self, with_postfix=True):529 token_type = self.stream.current.type530 lineno = self.stream.current.lineno531 if token_type == 'sub':532 next(self.stream)533- node = self.parse_unary()534- return nodes.Neg(node, lineno=lineno)535- if token_type == 'add':533+ node = nodes.Neg(self.parse_unary(False), lineno=lineno)534+ elif token_type == 'add':535 next(self.stream)537- node = self.parse_unary()538- return nodes.Pos(node, lineno=lineno)539- return self.parse_primary()536+ node = nodes.Pos(self.parse_unary(False), lineno=lineno)537+ else:538+ node = self.parse_primary()539+ if with_postfix:540+ node = self.parse_postfix(node)541+ return node542 541- def parse_primary(self, with_postfix=True):543+ def parse_primary(self):544 token = self.stream.current545 if token.type == 'name':546 if token.value in ('true', 'false', 'True', 'False'):547 node = nodes.Const(token.value in ('true', 'True'),23 unmodified lines571 elif token.type == 'lbrace':572 node = self.parse_dict()573 else:574 self.fail("unexpected '%s'" % describe_token(token), token.lineno)573- if with_postfix:574- node = self.parse_postfix(node)575 return node576 577 def parse_tuple(self, simplified=False, with_condexpr=True,578 extra_end_rules=None, explicit_parentheses=False):16 unmodified lines595 tuple is a valid expression or not.596 """597 lineno = self.stream.current.lineno598 if simplified:599- parse = lambda: self.parse_primary(with_postfix=False)599+ parse = self.parse_primary600 elif with_condexpr:601 parse = self.parse_expression602 else:603 parse = lambda: self.parse_expression(with_condexpr=False)279 unmodified linesmodified:CHANGES+1 added
16 unmodified lines17 compatibility the pure Python implementation still exists but is18 pulled from markupsafe by the Jinja2 developers. The debug support19 went into a separate feature called "debugsupport" and is disabled20 by default because it is only relevant for Python 2.421+- fixed an issue with unary operators having the wrong precendence.22 23 Version 2.524 -----------25 (codename Incoherence, relased on May 29th 2010)178 unmodified lines