Opened 14 years ago

Closed 14 years ago

Last modified 14 years ago

#8902 closed (duplicate)

tags having problems with filtered variables using arguments with spacing

Reported by: killiands Owned by: nobody
Component: Template system Version: 1.0
Severity: Keywords: template tags
Cc: Triage Stage: Unreviewed
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no


If you want to do something like this:
{% with activity.start_date|date:"l j F" as date1 %}
You'll get this error:
Exception Value: u'with' expected format is 'value as name'
This is due to this code:

    bits = list(token.split_contents())
    if len(bits) != 4 or bits[2] != "as":
        raise TemplateSyntaxError("%r expected format is 'value as name'" %

First of all, maybe another bug: split_contents gave me a double "" on a filter as |cut:" ", so I replaced it with contents.split() which worked fine for me.
Then, this error: len(bits) !=4 is actually overkill. The tag works like this: 0 -> tagname, 1-> a variable with filter, 2 -> as, 3 -> newvar. Actually you should not check if the ' '-splitted content is 4 long, you should check if [1] passes the compile_filter, which will throw it's own error.

I tried to write a regex or iteration that really checked if you did really passed 1 variable + filter(s), but that really isn't trivial, and the compile_filter function's error is actually clear enough.

I added a patch + test for the {% with %} tag only at the moment (because that's where I encountered the problem). However, other tags have the problem also.

Attachments (1)

with_patch_test.diff (1.9 KB) - added by killiands 14 years ago.
Patch + tests

Download all attachments as: .zip

Change History (4)

Changed 14 years ago by killiands

Attachment: with_patch_test.diff added

Patch + tests

comment:1 Changed 14 years ago by killiands

To be more precise, actually every tag that blindly splits on spaces will break on filter arguments with spaces in it. Such a patch would be quite large (all default tags, special tags & contrip apps tags).

Of course, Since the with tags works with my patch you can always work around this problem in other tags.

comment:2 Changed 14 years ago by dc

Resolution: duplicate
Status: newclosed

Duplicate of #6271.

comment:3 Changed 14 years ago by (none)

milestone: post-1.0

Milestone post-1.0 deleted

Note: See TracTickets for help on using tickets.
Back to Top