Opened 10 years ago

Closed 9 years ago

#4123 closed (fixed)

firstof template tag doesn't accept strings with spaces

Reported by: Wesley Fok <portland@…> Owned by: Matt Boersma
Component: Template system Version: master
Severity: Keywords: firstof
Cc: axiak@… Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

Description

When firstof is passed a quoted string with a space, ex. {% firstof var1 var2 var3 "fallback string" %}, it splits the string and reads the pieces as False. If the string is the last element in the firstof tag, then the whole thing returns False and firstof returns a blank string.

Attachments (2)

firstof_patch.diff (443 bytes) - added by Wesley Fok <portland@…> 10 years ago.
Simple patch for firstof compilation function.
4123.diff (2.2 KB) - added by Matt Boersma 9 years ago.
Patch with docs and tests for handling strings with spaces in the firstof tag.

Download all attachments as: .zip

Change History (7)

Changed 10 years ago by Wesley Fok <portland@…>

Attachment: firstof_patch.diff added

Simple patch for firstof compilation function.

comment:1 Changed 10 years ago by Michael Axiak <axiak@…>

Cc: axiak@… added
Has patch: set
Triage Stage: UnreviewedAccepted

This seems like an obvious bug and fix.
I hope someone with more clout can verify this.

comment:2 Changed 9 years ago by Matt Boersma

Owner: changed from nobody to Matt Boersma
Status: newassigned

comment:3 Changed 9 years ago by Matt Boersma

Needs tests: set
Triage Stage: AcceptedDesign decision needed

The docs for the firstof tag make no mention of accepting literal strings, only variables. So my first inclination was "wontfix."

On the other hand, similar tags like "if" seem to handle literal strings as if they were (always True) variables. And token.split_contents is a more reliable method that is used elsewhere and arguably should be here too. Finally, having a "fallback string" as described here seems quite useful, although if we went that we it implies a documentation change.

I'll be glad to make the doc changes if a core developer decides this is worth doing, otherwise we should close it as wontfix.

Changed 9 years ago by Matt Boersma

Attachment: 4123.diff added

Patch with docs and tests for handling strings with spaces in the firstof tag.

comment:4 Changed 9 years ago by Matt Boersma

Keywords: firstof added
Needs tests: unset
Triage Stage: Design decision neededReady for checkin

comment:5 Changed 9 years ago by Malcolm Tredinnick

Resolution: fixed
Status: assignedclosed

(In [6571]) Fixed #4123 -- Changed the firstof template tag to correctly handle a literal
string as its last argument. Thanks, Wesley Fok and Matt Boersma.

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