Repository navigation
gh-158978: Fix cloning of DOM Level 1 nodes in xml.dom.minidom - #158987
sricursion wants to merge 2 commits into
Conversation
cloneNode() and importNode() created the clones with createElementNS(), setAttributeNS() and createAttributeNS(), which now reject a prefixed name in no namespace. Create the Element and Attr nodes directly instead.
|
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 |
|
Thank you for the fix, but I would not bypass the factory methods of the document. All other branches of A DOM Level 1 node has no namespace, so it can be cloned with the DOM Level 1 methods, which only check the name: This also makes the clone more faithful: for Please add a NEWS entry. |
|
About the NEWS entry: it is not necessary, because gh-156665 is only in 3.16, and its own entry describes the resulting behaviour. It was already in an alpha release, so an entry is acceptable, but up to you. |
Clone nodes without a namespace with createElement(), setAttribute() and createAttribute(), and namespaced nodes with the NS variants, so that a Document subclass can create its own node classes and the clone keeps the prefix of the original. The tests now compare the names of the clone with those of the original.
|
Thanks, that's better. |
Node.cloneNode()andDocument.importNode()raiseNamespaceErrfor DOM Level 1 nodes that have a colon in the name, for examplecreateElement("svg:rect"),setAttribute("xmlns:xsi", ...),createAttribute("a:b"), or any node of a document parsed with namespaces disabled._clone_node()rebuilt every element and attribute withcreateElementNS(),setAttributeNS()andcreateAttributeNS(), and since gh-156665 those reject a prefixed name in no namespace. The same applies tosetAttribute("xmlns", ...), which is rejected as thexmlnsattribute in the wrong namespace. This is a regression in 3.16 only; 3.15 and earlier clone these nodes without error. Nodes without a namespace are now cloned with the DOM Level 1 factory methodscreateElement(),setAttribute()andcreateAttribute(), which only check the name, and namespaced nodes still with the NS variants, so the clone keeps the original'sprefix.There is no NEWS entry, since the entry for gh-156665 already describes the resulting behaviour.
xml.dom.minidom: cloneNode() and importNode() raise NamespaceErr for DOM Level 1 nodes #158978