Opened 17 years ago

Closed 17 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: dev
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: no UI/UX: no

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@…> 17 years ago.
Simple patch for firstof compilation function.
4123.diff (2.2 KB ) - added by Matt Boersma 17 years ago.
Patch with docs and tests for handling strings with spaces in the firstof tag.

Download all attachments as: .zip

Change History (7)

by Wesley Fok <portland@…>, 17 years ago

Attachment: firstof_patch.diff added

Simple patch for firstof compilation function.

comment:1 by Michael Axiak <axiak@…>, 17 years ago

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 by Matt Boersma, 17 years ago

Owner: changed from nobody to Matt Boersma
Status: newassigned

comment:3 by Matt Boersma, 17 years ago

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.

by Matt Boersma, 17 years ago

Attachment: 4123.diff added

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

comment:4 by Matt Boersma, 17 years ago

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

comment:5 by Malcolm Tredinnick, 17 years ago

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