Skip to content

gh-158208: Don't write a duplicate xmlns attribute in xml.dom.minidom - #158209

Open
fedonman wants to merge 2 commits into
python:mainfrom
fedonman:fix-minidom-duplicate-xmlns
Open

fedonman wants to merge 2 commits into
python:mainfrom
fedonman:fix-minidom-duplicate-xmlns

Conversation

@fedonman

@fedonman fedonman commented Sep 26, 2026 •

Copy link
Copy Markdown
Contributor

_fixup_namespaces() no longer adds xmlns="" to an element in no namespace that already has its own xmlns attribute. The default namespace is still treated as undeclared for the element's children, so they are written as before.

$ ./python -m test -v test_minidom | grep -E 'OwnDefault|Total tests|Result'
testWriteXMLOwnDefaultNamespaceDeclaration (test.test_minidom.MinidomTest.testWriteXMLOwnDefaultNamespaceDeclaration) ... ok
Total tests: run=157 skipped=1
Result: SUCCESS

…inidom

Since pythongh-44376, _fixup_namespaces() adds xmlns="" to an element in no
namespace under a default namespace.  When the element declares the
default namespace itself, as one built with createElement() and
setAttribute("xmlns", ...) does, its own xmlns attribute was written
too, so the output was not well-formed.

Do not add the undeclaration if the element already has an xmlns
attribute.  The default namespace is still treated as undeclared for
its children, so they are written as before.
@fedonman

fedonman commented Nov 3, 2026

Copy link
Copy Markdown
Contributor Author

@serhiy-storchaka, could you take a look when you have a moment? It fixes a regression from GH-156666.

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