Opened 6 years ago

Closed 3 years ago

#10931 closed Bug (fixed)

truncate_html_words doen't handle multi-line tags properly

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

Description

If you have the following in your HTML, for example:

<a class="offsite" href=
"http://blah.com/something/">

truncate_html_words will include all the words in the tag, as well as not close the tag properly if it needs to.

The attached patch simply adds the re.S flag for the two regular expressions used in the function.

Attachments (3)

utils_text-r10637.patch (683 bytes) - added by gsong 6 years ago.
Handle mutli-line tags
10931-utils_text-r10651.patch (4.2 KB) - added by gsong 6 years ago.
Updated patch with tests.
10931-3.diff (1.4 KB) - added by claudep 3 years ago.
Updated to current trunk

Download all attachments as: .zip

Change History (11)

Changed 6 years ago by gsong

Handle mutli-line tags

comment:1 Changed 6 years ago by SmileyChris

  • Needs documentation unset
  • Needs tests set
  • Patch needs improvement unset
  • Triage Stage changed from Unreviewed to Accepted

comment:2 Changed 6 years ago by gsong

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

Changed 6 years ago by gsong

Updated patch with tests.

comment:3 Changed 6 years ago by gsong

  • Needs tests unset

I've updated the patch with tests that are pretty comprehensive.

comment:4 Changed 6 years ago by gsong

  • Triage Stage changed from Accepted to Ready for checkin

comment:5 Changed 5 years ago by lukeplant

  • Patch needs improvement set
  • Triage Stage changed from Ready for checkin to Accepted

Thanks so much for this. However, the tests for this should be unit tests, as we are moving away from doctests, especially for this type of thing, and especially as there are already unit tests for truncate_html_words in tests/regressiontests/utils/tests.py. Just add to the ones there already.

Thanks.

comment:6 Changed 4 years ago by lukeplant

  • Severity set to Normal
  • Type set to Bug

Changed 3 years ago by claudep

Updated to current trunk

comment:7 Changed 3 years ago by claudep

  • Easy pickings unset
  • Owner gsong deleted
  • Patch needs improvement unset
  • Status changed from assigned to new
  • UI/UX unset

I only included the test that specifically addresses the new line issue.

comment:8 Changed 3 years ago by julien

  • Owner set to julien
  • Resolution set to fixed
  • Status changed from new to closed

In [17329]:

Fixed #10931 -- Made Truncator handle newlines properly. Thanks to gsong and Claude Paroz.

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