Opened 6 years ago

Closed 6 years ago

#29798 closed Uncategorized (invalid)

truncatewords_html fails on some self-closing tags

Reported by: Béranger Enselme Owned by: nobody
Component: Template system Version: 2.1
Severity: Normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

Also in 1.11...

>>> from django.template.defaultfilters import truncatewords_html
>>> truncatewords_html('<p class="alinea">one two three</p>', 2)
'<p class="alinea">one two ...</p>'
>>> truncatewords_html('<p class="alinea">one two three</p><p class="alinea"/><p class="alinea">four five</p>', 4)
'<p class="alinea">one two three</p><p class="alinea"/><p class="alinea">four ...</p></p>'

truncatewords_html will add tag closures for every self-closing tag that has at least an attribute.

Change History (1)

comment:1 by Carlton Gibson, 6 years ago

Resolution: invalid
Status: newclosed

I think this is invalid. If I pump your HTML fragment into the W3 HTML Validator (as HTML 5) I get (amongst errors about the document structure not being right) this:

Error: Self-closing syntax (/>) used on a non-void HTML element. Ignoring the slash and treating as a start tag.
From line 1, column 36; to line 1, column 54
three</p><p class="alinea"/><p cla

Looks like truncatewords_html's behaviour is correct.

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