[Django] #27022: some DjangoTemplates builtin tags misparse lack of whitespace between variable name and boolean operator in arguments

22 views
Skip to first unread message

Django

unread,
Aug 5, 2016, 2:28:45 AM8/5/16
to django-...@googlegroups.com
#27022: some DjangoTemplates builtin tags misparse lack of whitespace between
variable name and boolean operator in arguments
-------------------------+-------------------------------------------------
Reporter: cowbert | Owner: nobody
Type: Bug | Status: new
Component: | Version: 1.10
Template system | Keywords: tags, arguments, operators,
Severity: Normal | whitespace
Triage Stage: | Has patch: 0
Unreviewed |
Easy pickings: 0 | UI/UX: 0
-------------------------+-------------------------------------------------
The `django.DjangoTemplates` template backend is unable to parse a
comparison operator when there is no whitespace around the operator using
builtin tag `if`:

{{{#!python
{% if foo=='bar' %}
<!-- do something -->
{% endif %}
}}}

raises:

{{{
TemplateSyntaxError at url

Could not parse the remainder: '=='bar'' from 'foo=='bar''
}}}

At least one space is required on both sides of the `==` operator (So `foo
=='bar'` and `foo== 'bar'` throws `Could not parse the remainder:
'=='bar'' from '=='bar''` and `Could not parse the remainder: '==' from
'foo=='`, respectively). More than one space is acceptable.

This seems to affect the following boolean operators: `==`, `!=`, `<`,
`>`, `<=`, `>=`. My guess is the boolean expression tokenizer in
DjangoTemplates first tries split(' ') then ultimately evals ![0]![1]![2]
(but I haven't actually looked at the source to verify this).

--
Ticket URL: <https://code.djangoproject.com/ticket/27022>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Aug 5, 2016, 2:58:29 AM8/5/16
to django-...@googlegroups.com
#27022: some DjangoTemplates builtin tags misparse lack of whitespace between
variable name and boolean operator in arguments
-------------------------------------+-------------------------------------

Reporter: cowbert | Owner: nobody
Type: Bug | Status: new
Component: Template system | Version: 1.10
Severity: Normal | Resolution:
Keywords: tags, arguments, | Triage Stage: Accepted
operators, whitespace |
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by bmispelon):

* needs_better_patch: => 0
* needs_docs: => 0
* needs_tests: => 0
* stage: Unreviewed => Accepted


Comment:

Hi,

Indeed, the template language doesn't seem to support that. I'm not sure
if it ever did either (I went back as far as 1.6 and observed the same
error).

It'd be nice to be able to make this use-case work, so that we can match
the Python semantics a bit better.
However, if it's too tricky then this should be mentionned in the
documentation [1] at least.


Thanks.

[1] https://docs.djangoproject.com/en/dev/ref/templates/builtins/#boolean-
operators

--
Ticket URL: <https://code.djangoproject.com/ticket/27022#comment:1>

Django

unread,
Aug 5, 2016, 8:25:10 AM8/5/16
to django-...@googlegroups.com
#27022: some DjangoTemplates builtin tags misparse lack of whitespace between
variable name and boolean operator in arguments
-------------------------------------+-------------------------------------

Reporter: cowbert | Owner: nobody
Type: Bug | Status: new
Component: Template system | Version: 1.10
Severity: Normal | Resolution:
Keywords: tags, arguments, | Triage Stage: Accepted
operators, whitespace |
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by timgraham):

As for me, I'd rather not let it work so as to enforce a consistent style
in templates. Since all examples use this style, I don't see much need to
document that omitting the whitespace doesn't work. Is it difficult to
figure out what went wrong from the error message?

--
Ticket URL: <https://code.djangoproject.com/ticket/27022#comment:2>

Django

unread,
Nov 4, 2016, 5:31:49 PM11/4/16
to django-...@googlegroups.com
#27022: some DjangoTemplates builtin tags misparse lack of whitespace between
variable name and boolean operator in arguments
-------------------------------------+-------------------------------------
Reporter: Peter Lai | Owner: nobody
Type: Bug | Status: new

Component: Template system | Version: 1.10
Severity: Normal | Resolution:
Keywords: tags, arguments, | Triage Stage: Accepted
operators, whitespace |
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Anton Samarchyan):

Replying to [comment:2 Tim Graham]:


> As for me, I'd rather not let it work so as to enforce a consistent
style in templates. Since all examples use this style, I don't see much
need to document that omitting the whitespace doesn't work. Is it
difficult to figure out what went wrong from the error message?

I completely agree. Probably wontfix is the best option here.

--
Ticket URL: <https://code.djangoproject.com/ticket/27022#comment:3>

Django

unread,
Nov 5, 2016, 3:03:25 AM11/5/16
to django-...@googlegroups.com
#27022: some DjangoTemplates builtin tags misparse lack of whitespace between
variable name and boolean operator in arguments
-------------------------------------+-------------------------------------
Reporter: Peter Lai | Owner: nobody
Type: Bug | Status: closed

Component: Template system | Version: 1.10
Severity: Normal | Resolution: wontfix

Keywords: tags, arguments, | Triage Stage: Accepted
operators, whitespace |
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Tim Graham):

* status: new => closed
* resolution: => wontfix


--
Ticket URL: <https://code.djangoproject.com/ticket/27022#comment:4>

Reply all
Reply to author
Forward
0 new messages