Opened 10 years ago

Closed 8 years ago

Last modified 8 years ago

#1147 closed defect (wontfix)

[patch] Tags cannot contain newlines

Reported by: jim-django@… Owned by: adrian
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@… 10 years ago.
Patch to allow newlines inside tags
patch.2.diff (1.0 KB) - added by jim-django@… 10 years ago.
Patch to allow newlines inside tags (corrected)

Download all attachments as: .zip

Change History (13)

Changed 10 years ago by jim-django@…

Patch to allow newlines inside tags

Changed 10 years ago by jim-django@…

Patch to allow newlines inside tags (corrected)

comment:1 Changed 10 years ago by anonymous

  • Summary changed from Tags cannot contain newlines to [patch] Tags cannot contain newlines

comment:2 Changed 9 years ago by adrian

  • Resolution set to wontfix
  • Status changed from new to closed

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

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

  • Cc nslater@… added
  • Resolution wontfix deleted
  • Status changed from closed to reopened

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 8 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 8 years ago by mtredinnick

  • Resolution set to wontfix
  • Status changed from reopened to closed

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 8 years ago by Noah Slater <nslater@…>

  • Resolution wontfix deleted
  • Status changed from closed to reopened

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 8 years ago by anonymous

  • Resolution set to wontfix
  • Status changed from reopened to closed

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 8 years ago by mtredinnick

(Last comment was by me.)

comment:9 Changed 8 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 8 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