Opened 8 years ago
Closed 8 years ago
#26606 closed Bug (invalid)
'string_if_invalid' option does not work with custom filter
Reported by: | JOSEPH KIM | Owned by: | nobody |
---|---|---|---|
Component: | Template system | Version: | 1.9 |
Severity: | Normal | Keywords: | template, custom template filter |
Cc: | Triage Stage: | Unreviewed | |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
I use 'string_if_invalid' option to debug invalid context variable.
However, custom filter does not work when a context variable is invalid.
I attached sample project and you can see custom filter works when the context variables is valid.
Attachments (1)
Change History (8)
by , 8 years ago
Attachment: | invalid_string.zip added |
---|
comment:1 by , 8 years ago
tested other filters like 'lower' but, it doesn't work with other filters either.
comment:2 by , 8 years ago
I see this output. What output do you expect?
with filter __FOO__ filter works with valid foo context with tag tag works with __FOO__ tag works with valid foo context
comment:3 by , 8 years ago
if filter works with "string_if_invalid" option
the output should be
with filter filter works with __FOO__ filter works with valid foo context with tag tag works with __FOO__ tag works with valid foo context
follow-up: 5 comment:4 by , 8 years ago
I don't see an advantage to running string_if_valid
through template filters -- they might transform the value to some other output which would make it more difficult debug.
comment:5 by , 8 years ago
"string_if_invalid" option works perfectly with context variables, however, with request parameters, it makes redundant code.
Actually, I am supposed to get null string ("") when I don't need string of "string_if_invalid" especially handle request parameters.
for example, to get null string (or to escape invalid string)
as is
<input name="foo" type="text" value="{% if request.GET.foo %}{{ request.GET.foo }}{% endif %}">
want to
<input name="foo" type="text" value="{{ request.GET.foo|or_null }}">
comment:6 by , 8 years ago
I'm having trouble understanding how your last comment relates to our previous discussion.
Have you read the "For debug purposes only" note about string_if_invalid
? I get the sense that you may be trying to use string_if_invalid
for more than it's designed for.
comment:7 by , 8 years ago
Resolution: | → invalid |
---|---|
Status: | new → closed |
sample project of custom filter with 'string if invalid' option