Opened 4 years ago

Closed 4 years ago

#19693 closed Bug (fixed)

truncatewords_html closes <br/> <hr/> tags

Reported by: sneawo Owned by: jonathanl
Component: Template system Version: master
Severity: Normal Keywords:
Cc: sneawo Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

In [9]: ts = 'test<br/><hr/>test test'
In [10]: struncatewords_html(s, 2)
Out[10]: u'test<br/><hr/>test ...</hr/></br/>'

Change History (10)

comment:1 Changed 4 years ago by sneawo

Cc: sneawo added
Needs documentation: unset
Needs tests: unset
Patch needs improvement: unset

comment:2 Changed 4 years ago by sneawo

Summary: trancatewords_html duplicates <br/> <hr/> tagstrancatewords_html closes <br/> <hr/> tags

comment:3 Changed 4 years ago by reecelong

Owner: changed from nobody to reecelong
Status: newassigned

comment:4 Changed 4 years ago by reecelong

Summary: trancatewords_html closes <br/> <hr/> tagstruncatewords_html closes <br/> <hr/> tags

comment:5 Changed 4 years ago by sneawo

I think it can be fixed with updating re_tag in django.utils.text
re_tag = re.compile(r'<(/)?([^ ]+?)(?:(\s*/)| .*?)?>')

comment:6 Changed 4 years ago by reecelong

Could you possibly provide more information about this bug? The current description of this bug is not clear enough for me to attempt to replicate. Thanks!

comment:7 Changed 4 years ago by Aymeric Augustin

The report isn't accurate; to reproduce on master:

>>> from django.template.defaultfilters import truncatewords_html
>>> truncatewords_html('test<br/><hr/>test test', 2)
u'test<br/><hr/>test ...</hr/></br/>'

comment:8 Changed 4 years ago by Claude Paroz

Triage Stage: UnreviewedAccepted

comment:9 Changed 4 years ago by jonathanl

Has patch: set
Owner: changed from reecelong to jonathanl
Version: 1.4master

Made a pull request https://github.com/django/django/pull/716

Thanks sneawo for your suggestion. It worked.

comment:10 Changed 4 years ago by Claude Paroz <claude@…>

Resolution: fixed
Status: assignedclosed

In ac4faa6dc33407c93566884e53fa5d8ef44c0a2a:

Fixed #19693 -- Made truncatewords_html handle self-closing tags

Thanks sneawo for the report and Jonathan Loy for the patch.

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