Code

Opened 4 years ago

Closed 3 years ago

#14288 closed Bug (fixed)

Template filter: linebreaksbr doesn't normalize newlines

Reported by: michiel_1981 Owned by: nobody
Component: Template system Version: master
Severity: Normal Keywords:
Cc: Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

When linebreakbr filter encounters windows style newlines it leaves "Carriage return" behind.

Example Code

from django.template.defaultfilters import linebreaksbr
linebreaksbr(u'line 1\r\nline 2')

u'line 1\r<br />line 2'
which should be:
u'line 1\<br />line 2'

Attachments (4)

fix_windows_lineendings_breaking_linebreaksbr.patch (1.2 KB) - added by michiel_1981 4 years ago.
Patch
14288.linebreaksbr-normalized-newlines.diff (1.9 KB) - added by julien 3 years ago.
14288.linebreaksbr-normalized-newlines.2.diff (3.0 KB) - added by julien 3 years ago.
14288.linebreaksbr-normalized-newlines.3.diff (3.2 KB) - added by julien 3 years ago.
Patch updated to latest trunk

Download all attachments as: .zip

Change History (13)

Changed 4 years ago by michiel_1981

Patch

comment:1 Changed 3 years ago by dmoisset

  • Needs documentation unset
  • Needs tests unset
  • Owner changed from nobody to dmoisset
  • Patch needs improvement unset

triaging...

comment:2 Changed 3 years ago by dmoisset

  • Needs tests set

comment:3 Changed 3 years ago by dmoisset

  • Owner changed from dmoisset to nobody
  • Triage Stage changed from Unreviewed to Accepted

comment:4 Changed 3 years ago by julien

  • Severity set to Normal
  • Type set to Bug

Changed 3 years ago by julien

comment:5 Changed 3 years ago by julien

  • Easy pickings unset
  • Needs tests unset

The original patch had some issues as the autoescape option was determined after the newline normalisation. The new patch fixes that and adds a couple more tests.

comment:6 Changed 3 years ago by jezdez

  • Patch needs improvement set

Please use the utility django.utils.text.normalize_newlines to do this.

comment:7 Changed 3 years ago by julien

  • Patch needs improvement unset

Thank you, Jannis. I took the chance to make django.utils.html.linebreaks use it as well.

Changed 3 years ago by julien

Patch updated to latest trunk

comment:8 Changed 3 years ago by jezdez

  • Triage Stage changed from Accepted to Ready for checkin
  • UI/UX unset

comment:9 Changed 3 years ago by jezdez

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

In [16573]:

Fixed #14288 -- Fixed linebreaksbr template filter to normalize newlines first. Thanks, Julien Phalip.

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.