Opened 8 years ago

Closed 7 years ago

Last modified 4 years ago

#5270 closed (fixed)

Template tags won't accept an empty string as an argument

Reported by: stephen Owned by: jdunck
Component: Template system Version: master
Severity: Keywords: empty string tplrf-fixed
Cc: jdunck@… Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

Description

There currently appears to be no easy to pass an empty string to a template tag.

{% url admin "" %} results in a TemplateSyntaxError.

Some template tags (notable reverse URL lookups for the root of a newforms-admin instance) require an empty string to be passed in.

Attachments (2)

empty-string.patch (782 bytes) - added by rnairn@… 7 years ago.
Patch to allow empty constant strings as filter arguments
5270-empty-string-template-w-tests.diff (2.9 KB) - added by jdunck 7 years ago.
Added tests, and now handling the empty i18n constant specially for translation.

Download all attachments as: .zip

Change History (12)

comment:1 Changed 8 years ago by Simon G. <dev@…>

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Triage Stage changed from Unreviewed to Design decision needed

comment:2 Changed 8 years ago by miracle2k

This is due to

if i18n_constant:
    var = '"%s"' %  _(i18n_constant.replace(r'\"', '"'))
elif constant:
    var = '"%s"' % constant.replace(r'\"', '"')

in FilterExpression.init(), where the elif-clause should probably check for is None.

Would be nice if this could be fixed.

Changed 7 years ago by rnairn@…

Patch to allow empty constant strings as filter arguments

comment:3 Changed 7 years ago by r0wb0t

  • Has patch set
  • Owner changed from nobody to r0wb0t
  • Status changed from new to assigned

Added a patch

comment:4 Changed 7 years ago by emulbreh

  • Keywords tplrf-fixed added

This would be fixed by the refactoring proposed in #7806.

comment:5 Changed 7 years ago by jacob

  • milestone set to 1.0

Changed 7 years ago by jdunck

Added tests, and now handling the empty i18n constant specially for translation.

comment:6 Changed 7 years ago by jdunck

  • Cc jdunck@… added
  • Triage Stage changed from Design decision needed to Ready for checkin

comment:7 Changed 7 years ago by jdunck

  • Owner changed from r0wb0t to jdunck
  • Status changed from assigned to new

comment:8 Changed 7 years ago by jdunck

  • Status changed from new to assigned

comment:9 Changed 7 years ago by gwilson

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

(In [8393]) Fixed #5270 -- Allow template tags and filters to accept an emtpy string, patch from jdunck.

comment:10 Changed 4 years ago by jacob

  • milestone 1.0 deleted

Milestone 1.0 deleted

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