Opened 2 years ago

Closed 2 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 2 years ago by sneawo

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

comment:2 Changed 2 years ago by sneawo

  • Summary changed from trancatewords_html duplicates <br/> <hr/> tags to trancatewords_html closes <br/> <hr/> tags

comment:3 Changed 2 years ago by reecelong

  • Owner changed from nobody to reecelong
  • Status changed from new to assigned

comment:4 Changed 2 years ago by reecelong

  • Summary changed from trancatewords_html closes <br/> <hr/> tags to truncatewords_html closes <br/> <hr/> tags

comment:5 Changed 2 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 2 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 2 years ago by aaugustin

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 2 years ago by claudep

  • Triage Stage changed from Unreviewed to Accepted

comment:9 Changed 2 years ago by jonathanl

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

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

Thanks sneawo for your suggestion. It worked.

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

  • Resolution set to fixed
  • Status changed from assigned to closed

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