Opened 13 years ago
Closed 13 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:2 by , 13 years ago
| Owner: | changed from to |
|---|
comment:3 by , 13 years ago
| Resolution: | → invalid |
|---|---|
| Status: | new → closed |
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.
I suspect this is because SafeString (and SafeUnicode), since they are objects, are always true, regardless of the data they wrap.