Opened 9 years ago

Closed 8 years ago

Last modified 5 years ago

#5270 closed (fixed)

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

Reported by: stephen Owned by: Jeremy Dunck
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@… 8 years ago.
Patch to allow empty constant strings as filter arguments
5270-empty-string-template-w-tests.diff (2.9 KB) - added by Jeremy Dunck 8 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 9 years ago by Simon G. <dev@…>

Needs documentation: unset
Needs tests: unset
Patch needs improvement: unset
Triage Stage: UnreviewedDesign decision needed

comment:2 Changed 9 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 8 years ago by rnairn@…

Attachment: empty-string.patch added

Patch to allow empty constant strings as filter arguments

comment:3 Changed 8 years ago by Rowan Nairn

Has patch: set
Owner: changed from nobody to Rowan Nairn
Status: newassigned

Added a patch

comment:4 Changed 8 years ago by Johannes Dollinger

Keywords: tplrf-fixed added

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

comment:5 Changed 8 years ago by Jacob

milestone: 1.0

Changed 8 years ago by Jeremy Dunck

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

comment:6 Changed 8 years ago by Jeremy Dunck

Cc: jdunck@… added
Triage Stage: Design decision neededReady for checkin

comment:7 Changed 8 years ago by Jeremy Dunck

Owner: changed from Rowan Nairn to Jeremy Dunck
Status: assignednew

comment:8 Changed 8 years ago by Jeremy Dunck

Status: newassigned

comment:9 Changed 8 years ago by Gary Wilson

Resolution: fixed
Status: assignedclosed

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

comment:10 Changed 5 years ago by Jacob

milestone: 1.0

Milestone 1.0 deleted

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