Skip to content

gh-156658: Only XML white space characters are treated as white space - #156659

Merged
serhiy-storchaka merged 1 commit into
python:mainfrom
serhiy-storchaka:gh-156658-xml-whitespace
Sep 2, 2026
Merged

gh-156658: Only XML white space characters are treated as white space#156659
serhiy-storchaka merged 1 commit into
python:mainfrom
serhiy-storchaka:gh-156658-xml-whitespace

Conversation

@serhiy-storchaka

@serhiy-storchaka serhiy-storchaka commented Aug 30, 2026

Copy link
Copy Markdown
Member

XML defines white space as " \t\r\n" (XML 1.0, 2.3), but str.strip() also strips other characters, such as U+00A0. They are content, and were lost in:

  • ElementTree.indent(), which overwrote them with the indentation;
  • canonicalize(strip_text=True), which changed the canonical form;
  • xml.dom parsing with the whitespace-in-element-content feature turned off, which removed such text nodes from the document;
  • Text.isWhitespaceInElementContent, which reported them as ignorable white space.

… space

XML defines white space as " \t\r\n" (see XML 1.0, 2.3), but str.strip()
also strips other characters, such as U+00A0.  Such characters could be
lost in ElementTree.indent(), in canonicalize(strip_text=True), and when
parsing with the whitespace-in-element-content feature turned off.
@serhiy-storchaka serhiy-storchaka added needs backport to 3.13 bugs and security fixes needs backport to 3.14 bugs and security fixes needs backport to 3.15 pre-release feature fixes, bugs and security fixes labels Aug 30, 2026
@serhiy-storchaka
serhiy-storchaka merged commit e7c93b7 into python:main Sep 2, 2026
62 checks passed
@miss-islington-app

Copy link
Copy Markdown

Thanks @serhiy-storchaka for the PR 🌮🎉.. I'm working now to backport this PR to: 3.13, 3.14, 3.15.
🐍🍒⛏🤖

@serhiy-storchaka
serhiy-storchaka deleted the gh-156658-xml-whitespace branch September 2, 2026 12:30
@bedevere-app

bedevere-app Bot commented Sep 2, 2026

Copy link
Copy Markdown

GH-156825 is a backport of this pull request to the 3.15 branch.

@bedevere-app bedevere-app Bot removed the needs backport to 3.15 pre-release feature fixes, bugs and security fixes label Sep 2, 2026
@bedevere-app

bedevere-app Bot commented Sep 2, 2026

Copy link
Copy Markdown

GH-156826 is a backport of this pull request to the 3.14 branch.

@bedevere-app bedevere-app Bot removed the needs backport to 3.14 bugs and security fixes label Sep 2, 2026
@bedevere-app

bedevere-app Bot commented Sep 2, 2026

Copy link
Copy Markdown

GH-156827 is a backport of this pull request to the 3.13 branch.

@bedevere-app bedevere-app Bot removed the needs backport to 3.13 bugs and security fixes label Sep 2, 2026
serhiy-storchaka added a commit that referenced this pull request Sep 2, 2026
…e space (GH-156659) (GH-156827)

XML defines white space as " \t\r\n" (see XML 1.0, 2.3), but str.strip()
also strips other characters, such as U+00A0.  Such characters could be
lost in ElementTree.indent(), in canonicalize(strip_text=True), and when
parsing with the whitespace-in-element-content feature turned off.
(cherry picked from commit e7c93b7)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
serhiy-storchaka added a commit that referenced this pull request Sep 2, 2026
…e space (GH-156659) (GH-156826)

XML defines white space as " \t\r\n" (see XML 1.0, 2.3), but str.strip()
also strips other characters, such as U+00A0.  Such characters could be
lost in ElementTree.indent(), in canonicalize(strip_text=True), and when
parsing with the whitespace-in-element-content feature turned off.
(cherry picked from commit e7c93b7)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant