From: Steve Norum Date: Sat, 12 Jan 2019 16:39:49 +0000 (-0500) Subject: Fixing compiler handling of parens around boolean comparisons. X-Git-Tag: 2.11.0~51^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=eca6fbfd6f4f60d3503dba7253cfb941d0751365;p=thirdparty%2Fjinja.git Fixing compiler handling of parens around boolean comparisons. --- diff --git a/jinja2/compiler.py b/jinja2/compiler.py index 5135a771..c0eb2400 100644 --- a/jinja2/compiler.py +++ b/jinja2/compiler.py @@ -1529,9 +1529,11 @@ class CodeGenerator(NodeVisitor): @optimizeconst def visit_Compare(self, node, frame): + self.write('(') self.visit(node.expr, frame) for op in node.ops: self.visit(op, frame) + self.write(')') def visit_Operand(self, node, frame): self.write(' %s ' % operators[node.op]) diff --git a/tests/test_lexnparse.py b/tests/test_lexnparse.py index a61c1467..5c4c2737 100644 --- a/tests/test_lexnparse.py +++ b/tests/test_lexnparse.py @@ -332,6 +332,12 @@ class TestSyntax(object): '{{ 2 == 2 }}|{{ 1 <= 1 }}') assert tmpl.render() == 'True|True|True|True|True' + def test_compare_parens(self, env): + tmpl = env.from_string( + "{{ i*(j<5) }}" + ) + assert tmpl.render(i=2, j=3) == '2' + def test_inop(self, env): tmpl = env.from_string('{{ 1 in [1, 2, 3] }}|{{ 1 not in [1, 2, 3] }}') assert tmpl.render() == 'True|False'