Opened 6 years ago

Closed 5 years ago

#14288 closed Bug (fixed)

Template filter: linebreaksbr doesn't normalize newlines

Reported by: Michiel 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 6 years ago.
Patch
14288.linebreaksbr-normalized-newlines.diff (1.9 KB) - added by Julien Phalip 6 years ago.
14288.linebreaksbr-normalized-newlines.2.diff (3.0 KB) - added by Julien Phalip 6 years ago.
14288.linebreaksbr-normalized-newlines.3.diff (3.2 KB) - added by Julien Phalip 6 years ago.
Patch updated to latest trunk

Download all attachments as: .zip

Change History (13)

Changed 6 years ago by Michiel

Patch

comment:1 Changed 6 years ago by dmoisset

Owner: changed from nobody to dmoisset

triaging...

comment:2 Changed 6 years ago by dmoisset

Needs tests: set

comment:3 Changed 6 years ago by dmoisset

Owner: changed from dmoisset to nobody
Triage Stage: UnreviewedAccepted

comment:4 Changed 6 years ago by Julien Phalip

Severity: Normal
Type: Bug

Changed 6 years ago by Julien Phalip

comment:5 Changed 6 years ago by Julien Phalip

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 6 years ago by Jannis Leidel

Patch needs improvement: set

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

Changed 6 years ago by Julien Phalip

comment:7 Changed 6 years ago by Julien Phalip

Patch needs improvement: unset

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

Changed 6 years ago by Julien Phalip

Patch updated to latest trunk

comment:8 Changed 5 years ago by Jannis Leidel

Triage Stage: AcceptedReady for checkin
UI/UX: unset

comment:9 Changed 5 years ago by Jannis Leidel

Resolution: fixed
Status: newclosed

In [16573]:

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

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