Opened 9 years ago

Closed 9 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)

invalid_string.zip (19.1 KB ) - added by JOSEPH KIM 9 years ago.
sample project of custom filter with 'string if invalid' option

Download all attachments as: .zip

Change History (8)

by JOSEPH KIM, 9 years ago

Attachment: invalid_string.zip added

sample project of custom filter with 'string if invalid' option

comment:1 by JOSEPH KIM, 9 years ago

tested other filters like 'lower' but, it doesn't work with other filters either.

comment:2 by Tim Graham, 9 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 JOSEPH KIM, 9 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 

comment:4 by Tim Graham, 9 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.

in reply to:  4 comment:5 by JOSEPH KIM, 9 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 Tim Graham, 9 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 JOSEPH KIM, 9 years ago

Resolution: invalid
Status: newclosed
Note: See TracTickets for help on using tickets.
Back to Top