Opened 7 weeks ago

Closed 7 weeks ago

Last modified 7 weeks ago

#36341 closed Bug (fixed)

django.utils.text.wrap does not preserve newlines within text to be wrapped

Reported by: Matti Pohjanvirta Owned by: Matti Pohjanvirta
Component: Template system Version: 5.2
Severity: Release blocker Keywords:
Cc: Sarah Boyce 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

After the fix for CVE-2025-26699, django.utils.text.wrap and wordwrap template filter no longer preserve empty lines in between lines in a text that is wrapped.

Given a text with an intentional empty line between paragraphs to wrap:

First line

Second line

it is wrapped to:

First line
Second line

Change History (16)

comment:1 by Matti Pohjanvirta, 7 weeks ago

Has patch: set

comment:2 by Antoliny, 7 weeks ago

Owner: set to Matti Pohjanvirta
Status: newassigned

comment:3 by Natalia Bidart, 7 weeks ago

Severity: NormalRelease blocker
Triage Stage: UnreviewedAccepted

Hello Matti Pohjanvirta, thank you very much for taking the time to create this report. I can confirm this is a regression in 55d89e25f4115c5674cdd9b9bcba2bb2bb6d820b. I will review your patch shortly, could you please double check that the patch does not add any exploitable performance issues?

comment:4 by Natalia Bidart, 7 weeks ago

Needs documentation: set
Patch needs improvement: set

comment:5 by Natalia Bidart, 7 weeks ago

Cc: Sarah Boyce added

comment:6 by Natalia Bidart, 7 weeks ago

Related forum post.

comment:7 by Natalia Bidart, 7 weeks ago

Needs documentation: unset
Patch needs improvement: unset
Triage Stage: AcceptedReady for checkin

comment:8 by nessita <124304+nessita@…>, 7 weeks ago

Resolution: fixed
Status: assignedclosed

In 1e9db35:

Fixed #36341 -- Preserved whitespaces in wordwrap template filter.

Regression in 55d89e25f4115c5674cdd9b9bcba2bb2bb6d820b.

This work improves the django.utils.text.wrap() function to ensure that
empty lines and lines with whitespace only are kept instead of being
dropped.

Thanks Matti Pohjanvirta for the report and fix.

Co-authored-by: Natalia <124304+nessita@…>

comment:9 by Natalia <124304+nessita@…>, 7 weeks ago

In 305aa4d0:

[5.2.x] Fixed #36341 -- Preserved whitespaces in wordwrap template filter.

Regression in 55d89e25f4115c5674cdd9b9bcba2bb2bb6d820b.

This work improves the django.utils.text.wrap() function to ensure that
empty lines and lines with whitespace only are kept instead of being
dropped.

Thanks Matti Pohjanvirta for the report and fix.

Co-authored-by: Natalia <124304+nessita@…>

Backport of 1e9db35836d42a3c72f3d1015c2f302eb6fee046 from main.

comment:10 by Natalia Bidart, 7 weeks ago

After the PR merge I realized we need to backport this to 5.1 and 4.2 as well, I'll be preparing a PR with releases notes and backport both revisions.

comment:11 by GitHub <noreply@…>, 7 weeks ago

In c86242d6:

Refs #36341 -- Added release notes for 5.1.9 and 4.2.21 for fix in wordwrap template filter.

Revision 1e9db35836d42a3c72f3d1015c2f302eb6fee046 fixed a regression in
55d89e25f4115c5674cdd9b9bcba2bb2bb6d820b, which also needs to be
backported to the stable branches in extended support (5.1.x and 4.2.x).

comment:12 by Natalia <124304+nessita@…>, 7 weeks ago

In 7d80f70:

[5.2.x] Refs #36341 -- Added release notes for 5.1.9 and 4.2.21 for fix in wordwrap template filter.

Revision 1e9db35836d42a3c72f3d1015c2f302eb6fee046 fixed a regression in
55d89e25f4115c5674cdd9b9bcba2bb2bb6d820b, which also needs to be
backported to the stable branches in extended support (5.1.x and 4.2.x).

Backport of c86242d61ff81bddbead115c458c1eb532d43b43 from main.

comment:13 by Natalia <124304+nessita@…>, 7 weeks ago

In 09a1813:

[5.1.x] Fixed #36341 -- Preserved whitespaces in wordwrap template filter.

Regression in 55d89e25f4115c5674cdd9b9bcba2bb2bb6d820b.

This work improves the django.utils.text.wrap() function to ensure that
empty lines and lines with whitespace only are kept instead of being
dropped.

Thanks Matti Pohjanvirta for the report and fix.

Co-authored-by: Natalia <124304+nessita@…>

Backport of 1e9db35836d42a3c72f3d1015c2f302eb6fee046 from main.

comment:14 by Natalia <124304+nessita@…>, 7 weeks ago

In 660067f8:

[5.1.x] Refs #36341 -- Added release notes for 5.1.9 and 4.2.21 for fix in wordwrap template filter.

Revision 1e9db35836d42a3c72f3d1015c2f302eb6fee046 fixed a regression in
55d89e25f4115c5674cdd9b9bcba2bb2bb6d820b, which also needs to be
backported to the stable branches in extended support (5.1.x and 4.2.x).

Backport of c86242d61ff81bddbead115c458c1eb532d43b43 from main.

comment:15 by Natalia <124304+nessita@…>, 7 weeks ago

In e61e3daa:

[4.2.x] Fixed #36341 -- Preserved whitespaces in wordwrap template filter.

Regression in 55d89e25f4115c5674cdd9b9bcba2bb2bb6d820b.

This work improves the django.utils.text.wrap() function to ensure that
empty lines and lines with whitespace only are kept instead of being
dropped.

Thanks Matti Pohjanvirta for the report and fix.

Co-authored-by: Natalia <124304+nessita@…>

Backport of 1e9db35836d42a3c72f3d1015c2f302eb6fee046 from main.

comment:16 by Natalia <124304+nessita@…>, 7 weeks ago

In b3df753:

[4.2.x] Refs #36341 -- Added release note for 4.2.21 for fix in wordwrap template filter.

Revision 1e9db35836d42a3c72f3d1015c2f302eb6fee046 fixed a regression in
55d89e25f4115c5674cdd9b9bcba2bb2bb6d820b, which also needs to be
backported to the stable branches in extended support.

Backport of c86242d61ff81bddbead115c458c1eb532d43b43 from main.

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