Django

Code

Ticket #4123 (closed: fixed)

Opened 1 year ago

Last modified 1 year ago

firstof template tag doesn't accept strings with spaces

Reported by: Wesley Fok <portland@chrominance.net> Assigned to: mboersma
Milestone: Component: Template system
Version: SVN Keywords: firstof
Cc: axiak@mit.edu Triage Stage: Ready for checkin
Has patch: 1 Needs documentation: 0
Needs tests: 0 Patch needs improvement: 0

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

firstof_patch.diff (443 bytes) - added by Wesley Fok <portland@chrominance.net> on 04/22/07 22:26:01.
Simple patch for firstof compilation function.
4123.diff (2.2 kB) - added by mboersma on 09/21/07 01:37:29.
Patch with docs and tests for handling strings with spaces in the firstof tag.

Change History

04/22/07 22:26:01 changed by Wesley Fok <portland@chrominance.net>

  • attachment firstof_patch.diff added.

Simple patch for firstof compilation function.

04/25/07 18:25:38 changed by Michael Axiak <axiak@mit.edu>

  • cc set to axiak@mit.edu.
  • needs_better_patch changed.
  • needs_tests changed.
  • needs_docs changed.
  • has_patch set to 1.
  • stage changed from Unreviewed to Accepted.

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

09/15/07 12:11:13 changed by mboersma

  • owner changed from nobody to mboersma.
  • status changed from new to assigned.

09/15/07 12:38:40 changed by mboersma

  • needs_tests set to 1.
  • 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.

09/21/07 01:37:29 changed by mboersma

  • attachment 4123.diff added.

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

09/21/07 01:38:36 changed by mboersma

  • keywords set to firstof.
  • needs_tests deleted.
  • stage changed from Design decision needed to Ready for checkin.

10/20/07 10:01:32 changed by mtredinnick

  • status changed from assigned to closed.
  • resolution set to fixed.

(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/Change #4123 (firstof template tag doesn't accept strings with spaces)




Change Properties
Action