#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 |
Description
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'" % bits[0])
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)
Change History (4)
by , 16 years ago
Attachment: | with_patch_test.diff added |
---|
comment:1 by , 16 years ago
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.
Patch + tests