Skip to content

xml.dom.minidom does not validate namespaces #156665

Description

@serhiy-storchaka

xml.dom.minidom implements the namespace methods of DOM Level 2, but never raises NamespaceErr:

>>> doc.createElementNS(None, "p:e")            # a prefix without a namespace
>>> doc.createElementNS("http://x", "xml:e")    # the xml prefix in other namespace
>>> doc.createElementNS("http://x", "p:p:e")    # a malformed qualified name
>>> doc.createAttributeNS("http://x", "xmlns")  # xmlns in other namespace
>>> elem.setAttributeNS(None, "p:a", "v")

All these cases are required to raise NAMESPACE_ERR by DOM Level 2 Core and by the "validate and extract" algorithm of the WHATWG DOM Standard, which adds one more case: a name in the XMLNS namespace which is not xmlns.

The same checks are already implemented in DOMImplementation.createDocument() and createDocumentType(), they are only missing in the factory methods of Document and Element.

Also, prefix is writable and not validated (elem.prefix = "q:r" is accepted, as is the xml prefix in other namespace). Note that in the WHATWG DOM Standard prefix is read-only.

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    stdlibStandard Library Python modules in the Lib/ directorytopic-XMLtype-bugAn unexpected behavior, bug, or error

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions