Opened 12 years ago

Closed 12 years ago

#18385 closed Bug (invalid)

firstof doesn't deal well with empty "safe" values.

Reported by: Ned Batchelder Owned by: Martin Winkler
Component: Template system Version: 1.4
Severity: Normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

>>> from django.template import Context, Template
>>> t = Template("Value: {{ value|safe }}, Firstof: {% firstof value|safe 'Hello' %}")
>>> t.render(Context({}))
u'Value: , Firstof: None'

Here, {{ value|safe }} produced an empty string, but value|safe inside of firstof produced None.

Change History (3)

comment:1 by Ned Batchelder, 12 years ago

I suspect this is because SafeString (and SafeUnicode), since they are objects, are always true, regardless of the data they wrap.

Version 0, edited 12 years ago by Ned Batchelder (next)

comment:2 by Martin Winkler, 12 years ago

Owner: changed from nobody to Martin Winkler

comment:3 by Martin Winkler, 12 years ago

Resolution: invalid
Status: newclosed

according to the documentation of the firstof tag:

Outputs the first variable passed that is not False. Does NOT auto-escape variable values.

So the safe filter is unnecessary, because the results have to be safe anyway.

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