Skip to content

gh-158984: Fix xmlns:prefix attributes set with setAttribute() in minidom - #158989

Open
sricursion wants to merge 1 commit into
python:mainfrom
sricursion:minidom-xmlns-prefix-declaration
Open

sricursion wants to merge 1 commit into
python:mainfrom
sricursion:minidom-xmlns-prefix-declaration

Conversation

@sricursion

@sricursion sricursion commented Oct 7, 2026 •

Copy link
Copy Markdown

_fixup_namespaces() took the prefix of an existing namespace declaration from Attr.prefix. That is None for attributes created with the DOM Level 1 API (setAttribute(), createAttribute() or a document parsed without namespace processing), even if the name is xmlns:p, so the declaration was recorded for the default namespace. As a result createElementNS(ns, "p:root") followed by setAttribute("xmlns:p", ns) was written with a duplicate xmlns:p, an element in no namespace got a spurious xmlns="", and an element in the namespace bound to a prefix this way was written without its own xmlns. The prefix is now derived from the attribute name. This fixes a problem introduced in gh-44376, which is not released yet, so there is no NEWS entry. It is independent of gh-158208, which concerns a plain xmlns attribute.

…in minidom

Take the prefix of an existing namespace declaration from the attribute
name instead of Attr.prefix, which is None for attributes created with
the DOM Level 1 API.
@python-cla-bot

python-cla-bot Bot commented Oct 7, 2026 •

Copy link
Copy Markdown

All commit authors signed the Contributor License Agreement.

CLA signed

@bedevere-app

bedevere-app Bot commented Oct 7, 2026

Copy link
Copy Markdown

Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool.

If this change has little impact on Python users, wait for a maintainer to apply the skip news label instead.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant