Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bad comparison parsing for constants #1102

Closed
areebbeigh opened this issue Nov 12, 2019 · 1 comment · Fixed by #1105
Closed

Bad comparison parsing for constants #1102

areebbeigh opened this issue Nov 12, 2019 · 1 comment · Fixed by #1105
Milestone

Comments

@areebbeigh
Copy link
Contributor

@areebbeigh areebbeigh commented Nov 12, 2019

Comparisons in jinja don't behave like comparisons in Python.

template = '''{{4 < 2 < 3}}
{{a < b < c}}'''
t = Template(template)
print(t.render(a = 4, b = 2, c = 3))

Expected output:

False
False

Output:

True
False

Python code:

4 < 2 < 3

Output: False

The problem lies in

jinja/jinja2/nodes.py

Lines 775 to 780 in 1af1205

try:
for op in self.ops:
new_value = op.expr.as_const(eval_ctx)
result = _cmpop_to_func[op.op](value, new_value)
value = new_value
except Exception:

where the result of the comparison depends only on the final operator result.

I would like to submit a PR for this.

  • Python version: 3.6.7
  • Jinja version: 2.10
@davidism

This comment has been minimized.

Copy link
Member

@davidism davidism commented Nov 13, 2019

I would like to submit a PR for this.

PRs welcome

areebbeigh added a commit to areebbeigh/jinja that referenced this issue Nov 15, 2019
@davidism davidism added this to the 2.11.0 milestone Nov 20, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Linked pull requests

Successfully merging a pull request may close this issue.

2 participants
You can’t perform that action at this time.