Skip to content

ext/dom: Register id attributes set via setAttribute() in XML documents - #23801

Open
iliaal wants to merge 1 commit into
php:masterfrom
iliaal:fix/dom-setattribute-id-master
Open

iliaal wants to merge 1 commit into
php:masterfrom
iliaal:fix/dom-setattribute-id-master

Conversation

@iliaal

@iliaal iliaal commented Sep 20, 2026

Copy link
Copy Markdown
Member

dom_check_register_attribute_id() sets XML_ATTRIBUTE_ID only when the document is XML_HTML_DOCUMENT_NODE, so Dom\XMLDocument::getElementById() returns null after setAttribute("id", ...) even though the id property registered fine. Dropping the document-type restriction lets modern XML documents register an un-namespaced id attribute, setIdAttribute(false) still unregisters, and legacy DOMDocument is unchanged because every helper call site sits behind spec mode. All three call sites were audited.

getElementById() relies on the XML_ATTRIBUTE_ID flag, which
dom_check_register_attribute_id() set only for HTML documents, leaving
Dom\XMLDocument::getElementById() blind to ids assigned through
setAttribute(), setAttributeNS() and setAttributeNode(). Drop the
document-type restriction so modern XML documents register an un-namespaced
id attribute; setIdAttribute(false) still unregisters and legacy
DOMDocument is unchanged because every call site sits behind spec mode.
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