Opened 11 years ago

Closed 10 years ago

Last modified 9 years ago

#1147 closed defect (wontfix)

[patch] Tags cannot contain newlines

Reported by: jim-django@… Owned by: Adrian Holovaty
Component: Template system Version:
Severity: normal Keywords:
Cc: nslater@… Triage Stage: Unreviewed
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

Description

>>> t1 = Template("""It is the {% now "jS of F" %}""")
>>> t2 = Template("""It is the {% now
... "jS of F" %}""")
>>> t1.render(Context())
'It is the 31st o2:27 December'
>>> t2.render(Context())
'It is the {% now\n"jS of F" %}'

(Note also that the {% now %} I've taken from it's own documentation is a bit broken)

Attachments (2)

patch.diff (810 bytes) - added by jim-django@… 11 years ago.
Patch to allow newlines inside tags
patch.2.diff (1.0 KB) - added by jim-django@… 11 years ago.
Patch to allow newlines inside tags (corrected)

Download all attachments as: .zip

Change History (13)

Changed 11 years ago by jim-django@…

Attachment: patch.diff added

Patch to allow newlines inside tags

Changed 11 years ago by jim-django@…

Attachment: patch.2.diff added

Patch to allow newlines inside tags (corrected)

comment:1 Changed 11 years ago by anonymous

Summary: Tags cannot contain newlines[patch] Tags cannot contain newlines

comment:2 Changed 11 years ago by Adrian Holovaty

Resolution: wontfix
Status: newclosed

I don't see a reason why tags should include newlines. Marking as a wontfix.

comment:3 Changed 10 years ago by Noah Slater <nslater@…>

Cc: nslater@… added
Resolution: wontfix
Status: closedreopened

Adrian, can you provide more of an argument other than your personal opinion? There are many instances where I have very long tags or nested tags and this forces me to have lines that wrap 2,3 sometimes 4 times on a 80 character width display.

comment:4 Changed 10 years ago by Noah Slater <nslater@…>

Here is an example of an occasion where I would like to be able to use newlines:

<a href="{{ related_object.uri }}keywords/" title="{% if related_object.get_profile %}All {% ifequal user related_object %}your{% else %}{{ related_object.get_profile.name_possessive }}{% endifequal %} {{ related_object.verbose_name }} {% if contacts %}contacts {% endif%}favorite keywords{% else %}All keywords for this {{ related_object.verbose_name }}{% endif %}">...</a>

comment:5 Changed 10 years ago by Malcolm Tredinnick

Resolution: wontfix
Status: reopenedclosed

You cannot wrap inside a tag, but there is nothing to stop you wrapping between tags. So the above line can be broken at any number of points. Right after any %}, for example.

comment:6 Changed 10 years ago by Noah Slater <nslater@…>

Resolution: wontfix
Status: closedreopened

No, you are mistaken.

If you take a look at my example again you will see that the template tags occur in an element's attribute value, I.E. between quote characters and hence cannot contain newlines.

comment:7 Changed 10 years ago by anonymous

Resolution: wontfix
Status: reopenedclosed

Newlines are permitted inside attribute values both in SGML and XML.

Please refrain from reopening this ticket. If you have a genuine case that does not work, post it to django-users list and somebody there can help you to get it to work.

comment:8 Changed 10 years ago by Malcolm Tredinnick

(Last comment was by me.)

comment:9 Changed 10 years ago by anonymous

If the value is the value attribute of a hidden form element, you've just ensured that it will be posted with an embedded newline. If this is a session id or similar, chances are it won't match an existing session, and will be rejected.

And sure, this could be fixed in the view by stripping newlines/ other white space (although this is not without its problems), but the justification for not allowing tags to contain newlines seems arbitrary at best.

comment:10 Changed 10 years ago by anonymous

Agreed, just because newlines are permitted does not mean that is desirable.

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