Skip to content

gh-161110: Make minidom getElementById() stable for duplicate IDs - #161111

Merged
gpshead merged 1 commit into
python:mainfrom
gpshead:minidom-getelementbyid-order
Nov 1, 2026
Merged

gpshead merged 1 commit into
python:mainfrom
gpshead:minidom-getelementbyid-order

Conversation

@gpshead

@gpshead gpshead commented Nov 1, 2026 •

Copy link
Copy Markdown
Member

Document.getElementById() now visits child nodes in document order and only caches the first element seen for each ID, so for duplicate IDs it returns the first element in document order and keeps returning it until the document is modified. This matches the WHATWG DOM and libxml2. Documents with unique IDs are unaffected; for documents with duplicate IDs the returned element changes, so this is not meant for backport.

Fixes #161110

ANT-2026-C52DMQ8Z

Visit child nodes in document order and keep the first cached element
for each ID, so the first element in document order is returned.
@read-the-docs-community

Copy link
Copy Markdown

Documentation build overview

📚 cpython-previews | 🛠️ Build #35563435 | 📁 Comparing 3f5d710 against main (e9f37a3)

  🔍 Preview build  

2 files changed
± library/xml.dom.html
± whatsnew/changelog.html

@gpshead
gpshead merged commit 3735833 into python:main Nov 1, 2026
58 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

xml.dom.minidom.Document.getElementById() result for duplicate IDs depends on earlier lookups

1 participant