Opened 18 years ago
Closed 18 years ago
#3670 closed (fixed)
ifequal and ifnotequal failing with negative numbers
Reported by: | Owned by: | Adrian Holovaty | |
---|---|---|---|
Component: | Template system | Version: | dev |
Severity: | Keywords: | ifequal ifnotequal negative | |
Cc: | Triage Stage: | Ready for checkin | |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
{% ifequal -1 -20 %} hello {% endifequal %}
prints "hello"
{% ifnotequal -1 -1 %} hello {% endifnotequal %}
doesn't print anything
this because in resolve_variable( ) in django.template.init uses:
if path[0].isdigit():
which could be:
if path[0].isdigit() or path[0] == "-":
Attachments (3)
Change History (10)
by , 18 years ago
Attachment: | templateif_patch.patch added |
---|
comment:1 by , 18 years ago
comment:2 by , 18 years ago
Needs tests: | set |
---|---|
Patch needs improvement: | set |
This patch doesn't handle the case of {% ifequal foo -elephant %}
sensibly. It will try to process "-elephant" as if it were a number. I realise that is an error in any case, but we shouldn't confuse things further.
comment:3 by , 18 years ago
Triage Stage: | Unreviewed → Accepted |
---|
by , 18 years ago
Attachment: | numeric.patch added |
---|
by , 18 years ago
Attachment: | numeric_with_negative.patch added |
---|
comment:4 by , 18 years ago
Needs tests: | unset |
---|---|
Patch needs improvement: | unset |
Triage Stage: | Accepted → Ready for checkin |
Straightforward enough.
comment:5 by , 18 years ago
We run this piece of code a *lot* (for every argument in every template tag), so speed is important. I'm going to hold off committing whilst I do some timing tests on different approaches. No need to rewrite the patch in any way -- it's correct on a functional level. I just want to try out a few options whilst we're playing in this area.
comment:6 by , 18 years ago
The reg-exp seems to be fastest here. I tried a couple of ways of removing the double scan over the string in the case of numbers (we do a reg-exp pass and then a pass for '.'), but it added more code than speed-ups and wasn't worth it.
comment:7 by , 18 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
that should have been:
prints nothing