Skip to content

gh-159637: Fix renaming an attribute to a prefixed name in minidom - #159638

Open
fedonman wants to merge 1 commit into
python:mainfrom
fedonman:fix-minidom-rename-attr-prefix
Open

fedonman wants to merge 1 commit into
python:mainfrom
fedonman:fix-minidom-rename-attr-prefix

Conversation

@fedonman

@fedonman fedonman commented Oct 17, 2026 •

Copy link
Copy Markdown
Contributor

Document.renameNode() now sets the new namespace of an attribute before its prefix, so the prefix is checked against the namespace it is being renamed into. The prefix is also checked before the attribute is removed from its element, so a rejected rename leaves the element unchanged.

$ ./python -m test test_minidom -m testRenameAttributeToPrefixedName -v
testRenameAttributeToPrefixedName (test.test_minidom.MinidomTest.testRenameAttributeToPrefixedName) ... ok

$ ./python -m test test_minidom
Total tests: run=157 skipped=1
Total test files: run=1/1
Result: SUCCESS

No NEWS entry: this fixes a regression from gh-156665, which is new in 3.16.

Document.renameNode() set the new prefix of an attribute before its
new namespace, so the prefix was validated against the old namespace.
Renaming an attribute with no namespace to a prefixed name in a
namespace raised NamespaceErr after the attribute had been removed
from its element.

Set the namespace first, and check the prefix before removing the
attribute, so that a rejected rename leaves the element unchanged.
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