Code

Opened 7 years ago

Closed 7 years ago

#4123 closed (fixed)

firstof template tag doesn't accept strings with spaces

Reported by: Wesley Fok <portland@…> Owned by: mboersma
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@…> 7 years ago.
Simple patch for firstof compilation function.
4123.diff (2.2 KB) - added by mboersma 7 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 7 years ago by Wesley Fok <portland@…>

Simple patch for firstof compilation function.

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

  • Cc axiak@… added
  • Has patch set
  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Triage Stage changed from Unreviewed to Accepted

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

comment:2 Changed 7 years ago by mboersma

  • Owner changed from nobody to mboersma
  • Status changed from new to assigned

comment:3 Changed 7 years ago by mboersma

  • Needs tests set
  • Triage Stage changed from Accepted to Design 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 7 years ago by mboersma

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

comment:4 Changed 7 years ago by mboersma

  • Keywords firstof added
  • Needs tests unset
  • Triage Stage changed from Design decision needed to Ready for checkin

comment:5 Changed 7 years ago by mtredinnick

  • Resolution set to fixed
  • Status changed from assigned to closed

(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.

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.