[Django] #36341: django.utils.text.wrap does not preserve newlines within text to be wrapped

47 views
Skip to first unread message

Django

unread,
Apr 20, 2025, 10:20:03 AM4/20/25
to django-...@googlegroups.com
#36341: django.utils.text.wrap does not preserve newlines within text to be wrapped
-------------------------------------+-------------------------------------
Reporter: Matti Pohjanvirta | Type: Bug
Status: new | Component: Template
| system
Version: 5.2 | Severity: Normal
Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
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
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/36341>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Apr 20, 2025, 12:02:48 PM4/20/25
to django-...@googlegroups.com
#36341: django.utils.text.wrap does not preserve newlines within text to be wrapped
-----------------------------------+--------------------------------------
Reporter: Matti Pohjanvirta | Owner: (none)
Type: Bug | Status: new
Component: Template system | Version: 5.2
Severity: Normal | Resolution:
Keywords: | Triage Stage: Unreviewed
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-----------------------------------+--------------------------------------
Changes (by Matti Pohjanvirta):

* has_patch: 0 => 1

--
Ticket URL: <https://code.djangoproject.com/ticket/36341#comment:1>

Django

unread,
Apr 21, 2025, 6:56:21 AM4/21/25
to django-...@googlegroups.com
#36341: django.utils.text.wrap does not preserve newlines within text to be wrapped
-------------------------------------+-------------------------------------
Reporter: Matti Pohjanvirta | Owner: Matti
| Pohjanvirta
Type: Bug | Status: assigned
Component: Template system | Version: 5.2
Severity: Normal | Resolution:
Keywords: | Triage Stage:
| Unreviewed
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Antoliny):

* owner: (none) => Matti Pohjanvirta
* status: new => assigned

--
Ticket URL: <https://code.djangoproject.com/ticket/36341#comment:2>

Django

unread,
Apr 21, 2025, 3:20:03 PM4/21/25
to django-...@googlegroups.com
#36341: django.utils.text.wrap does not preserve newlines within text to be wrapped
-------------------------------------+-------------------------------------
Reporter: Matti Pohjanvirta | Owner: Matti
| Pohjanvirta
Type: Bug | Status: assigned
Component: Template system | Version: 5.2
Severity: Release blocker | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Natalia Bidart):

* severity: Normal => Release blocker
* stage: Unreviewed => Accepted

Comment:

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?
--
Ticket URL: <https://code.djangoproject.com/ticket/36341#comment:3>

Django

unread,
Apr 21, 2025, 9:20:28 PM4/21/25
to django-...@googlegroups.com
#36341: django.utils.text.wrap does not preserve newlines within text to be wrapped
-------------------------------------+-------------------------------------
Reporter: Matti Pohjanvirta | Owner: Matti
| Pohjanvirta
Type: Bug | Status: assigned
Component: Template system | Version: 5.2
Severity: Release blocker | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 1
Needs tests: 0 | Patch needs improvement: 1
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Natalia Bidart):

* needs_better_patch: 0 => 1
* needs_docs: 0 => 1

--
Ticket URL: <https://code.djangoproject.com/ticket/36341#comment:4>

Django

unread,
Apr 21, 2025, 9:20:52 PM4/21/25
to django-...@googlegroups.com
#36341: django.utils.text.wrap does not preserve newlines within text to be wrapped
-------------------------------------+-------------------------------------
Reporter: Matti Pohjanvirta | Owner: Matti
| Pohjanvirta
Type: Bug | Status: assigned
Component: Template system | Version: 5.2
Severity: Release blocker | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 1
Needs tests: 0 | Patch needs improvement: 1
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Natalia Bidart):

* cc: Sarah Boyce (added)

--
Ticket URL: <https://code.djangoproject.com/ticket/36341#comment:5>

Django

unread,
Apr 22, 2025, 10:43:04 AM4/22/25
to django-...@googlegroups.com
#36341: django.utils.text.wrap does not preserve newlines within text to be wrapped
-------------------------------------+-------------------------------------
Reporter: Matti Pohjanvirta | Owner: Matti
| Pohjanvirta
Type: Bug | Status: assigned
Component: Template system | Version: 5.2
Severity: Release blocker | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 1
Needs tests: 0 | Patch needs improvement: 1
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Comment (by Natalia Bidart):

Related [https://forum.djangoproject.com/t/handling-whitespace-in-
wordwrap-after-cve-fix/40575 forum post].
--
Ticket URL: <https://code.djangoproject.com/ticket/36341#comment:6>

Django

unread,
Apr 23, 2025, 11:33:29 AM4/23/25
to django-...@googlegroups.com
#36341: django.utils.text.wrap does not preserve newlines within text to be wrapped
-------------------------------------+-------------------------------------
Reporter: Matti Pohjanvirta | Owner: Matti
| Pohjanvirta
Type: Bug | Status: assigned
Component: Template system | Version: 5.2
Severity: Release blocker | Resolution:
Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Natalia Bidart):

* needs_better_patch: 1 => 0
* needs_docs: 1 => 0
* stage: Accepted => Ready for checkin

--
Ticket URL: <https://code.djangoproject.com/ticket/36341#comment:7>

Django

unread,
Apr 23, 2025, 3:14:16 PM4/23/25
to django-...@googlegroups.com
#36341: django.utils.text.wrap does not preserve newlines within text to be wrapped
-------------------------------------+-------------------------------------
Reporter: Matti Pohjanvirta | Owner: Matti
| Pohjanvirta
Type: Bug | Status: closed
Component: Template system | Version: 5.2
Severity: Release blocker | Resolution: fixed
Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by nessita <124304+nessita@…>):

* resolution: => fixed
* status: assigned => closed

Comment:

In [changeset:"1e9db35836d42a3c72f3d1015c2f302eb6fee046" 1e9db35]:
{{{#!CommitTicketReference repository=""
revision="1e9db35836d42a3c72f3d1015c2f302eb6fee046"
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+...@users.noreply.github.com>
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/36341#comment:8>

Django

unread,
Apr 23, 2025, 3:19:34 PM4/23/25
to django-...@googlegroups.com
#36341: django.utils.text.wrap does not preserve newlines within text to be wrapped
-------------------------------------+-------------------------------------
Reporter: Matti Pohjanvirta | Owner: Matti
| Pohjanvirta
Type: Bug | Status: closed
Component: Template system | Version: 5.2
Severity: Release blocker | Resolution: fixed
Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Comment (by Natalia <124304+nessita@…>):

In [changeset:"305aa4d0c5507072fa3a1c2f03fba9559329b499" 305aa4d0]:
{{{#!CommitTicketReference repository=""
revision="305aa4d0c5507072fa3a1c2f03fba9559329b499"
[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+...@users.noreply.github.com>

Backport of 1e9db35836d42a3c72f3d1015c2f302eb6fee046 from main.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/36341#comment:9>

Django

unread,
Apr 23, 2025, 3:21:28 PM4/23/25
to django-...@googlegroups.com
#36341: django.utils.text.wrap does not preserve newlines within text to be wrapped
-------------------------------------+-------------------------------------
Reporter: Matti Pohjanvirta | Owner: Matti
| Pohjanvirta
Type: Bug | Status: closed
Component: Template system | Version: 5.2
Severity: Release blocker | Resolution: fixed
Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Comment (by Natalia Bidart):

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.
--
Ticket URL: <https://code.djangoproject.com/ticket/36341#comment:10>

Django

unread,
Apr 23, 2025, 4:27:09 PM4/23/25
to django-...@googlegroups.com
#36341: django.utils.text.wrap does not preserve newlines within text to be wrapped
-------------------------------------+-------------------------------------
Reporter: Matti Pohjanvirta | Owner: Matti
| Pohjanvirta
Type: Bug | Status: closed
Component: Template system | Version: 5.2
Severity: Release blocker | Resolution: fixed
Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Comment (by GitHub <noreply@…>):

In [changeset:"c86242d61ff81bddbead115c458c1eb532d43b43" c86242d6]:
{{{#!CommitTicketReference repository=""
revision="c86242d61ff81bddbead115c458c1eb532d43b43"
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).
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/36341#comment:11>

Django

unread,
Apr 23, 2025, 4:28:37 PM4/23/25
to django-...@googlegroups.com
#36341: django.utils.text.wrap does not preserve newlines within text to be wrapped
-------------------------------------+-------------------------------------
Reporter: Matti Pohjanvirta | Owner: Matti
| Pohjanvirta
Type: Bug | Status: closed
Component: Template system | Version: 5.2
Severity: Release blocker | Resolution: fixed
Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Comment (by Natalia <124304+nessita@…>):

In [changeset:"7d80f70988d96b39bd613c755b91bdf7355c1d71" 7d80f70]:
{{{#!CommitTicketReference repository=""
revision="7d80f70988d96b39bd613c755b91bdf7355c1d71"
[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.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/36341#comment:12>

Django

unread,
Apr 23, 2025, 4:30:41 PM4/23/25
to django-...@googlegroups.com
#36341: django.utils.text.wrap does not preserve newlines within text to be wrapped
-------------------------------------+-------------------------------------
Reporter: Matti Pohjanvirta | Owner: Matti
| Pohjanvirta
Type: Bug | Status: closed
Component: Template system | Version: 5.2
Severity: Release blocker | Resolution: fixed
Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Comment (by Natalia <124304+nessita@…>):

In [changeset:"09a1813cb8de0eaf8af8d612a223532dd6254b1f" 09a1813]:
{{{#!CommitTicketReference repository=""
revision="09a1813cb8de0eaf8af8d612a223532dd6254b1f"
[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+...@users.noreply.github.com>

Backport of 1e9db35836d42a3c72f3d1015c2f302eb6fee046 from main.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/36341#comment:13>

Django

unread,
Apr 23, 2025, 4:30:41 PM4/23/25
to django-...@googlegroups.com
#36341: django.utils.text.wrap does not preserve newlines within text to be wrapped
-------------------------------------+-------------------------------------
Reporter: Matti Pohjanvirta | Owner: Matti
| Pohjanvirta
Type: Bug | Status: closed
Component: Template system | Version: 5.2
Severity: Release blocker | Resolution: fixed
Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Comment (by Natalia <124304+nessita@…>):

In [changeset:"660067f8e7a61e9877c5c8977f8401b00b6c9d9d" 660067f8]:
{{{#!CommitTicketReference repository=""
revision="660067f8e7a61e9877c5c8977f8401b00b6c9d9d"
[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.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/36341#comment:14>

Django

unread,
Apr 23, 2025, 4:36:14 PM4/23/25
to django-...@googlegroups.com
#36341: django.utils.text.wrap does not preserve newlines within text to be wrapped
-------------------------------------+-------------------------------------
Reporter: Matti Pohjanvirta | Owner: Matti
| Pohjanvirta
Type: Bug | Status: closed
Component: Template system | Version: 5.2
Severity: Release blocker | Resolution: fixed
Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Comment (by Natalia <124304+nessita@…>):

In [changeset:"e61e3daaf037507211028494d61f24382be31e5a" e61e3daa]:
{{{#!CommitTicketReference repository=""
revision="e61e3daaf037507211028494d61f24382be31e5a"
[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+...@users.noreply.github.com>

Backport of 1e9db35836d42a3c72f3d1015c2f302eb6fee046 from main.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/36341#comment:15>

Django

unread,
Apr 23, 2025, 4:36:14 PM4/23/25
to django-...@googlegroups.com
#36341: django.utils.text.wrap does not preserve newlines within text to be wrapped
-------------------------------------+-------------------------------------
Reporter: Matti Pohjanvirta | Owner: Matti
| Pohjanvirta
Type: Bug | Status: closed
Component: Template system | Version: 5.2
Severity: Release blocker | Resolution: fixed
Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Comment (by Natalia <124304+nessita@…>):

In [changeset:"b3df75339904fb0bc5742d0b458ac59b8e68835b" b3df753]:
{{{#!CommitTicketReference repository=""
revision="b3df75339904fb0bc5742d0b458ac59b8e68835b"
[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.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/36341#comment:16>
Reply all
Reply to author
Forward
0 new messages