Skip to content

Commit 77858ae

Browse files
committed
Merge branch 'PHP-8.5'
* PHP-8.5: Fix phpGH-20281: \Dom\Document::getElementById() is inconsistent after nodes are removed
2 parents af3f150 + 6267bde commit 77858ae

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

ext/dom/html5_parser.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,10 @@ static lexbor_libxml2_bridge_status lexbor_libxml2_bridge_convert(
268268

269269
/* xmlIsID does some other stuff too that is irrelevant here. */
270270
if (local_name_length == 2 && local_name[0] == 'i' && local_name[1] == 'd' && attr->node.ns == LXB_NS_HTML) {
271-
xmlAddID(NULL, lxml_doc, value, lxml_attr);
271+
if (xmlAddID(NULL, lxml_doc, value, lxml_attr) == 0) {
272+
/* If the ID already exists, the ID attribute still needs to be marked as an ID. */
273+
lxml_attr->atype = XML_ATTRIBUTE_ID;
274+
}
272275
}
273276

274277
/* libxml2 doesn't support line numbers on this anyway, it derives them instead, so don't bother */
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
--TEST--
2+
GH-20281 (\Dom\Document::getElementById() is inconsistent after nodes are removed)
3+
--EXTENSIONS--
4+
dom
5+
--CREDITS--
6+
cscott
7+
--FILE--
8+
<?php
9+
$d = \Dom\HTMLDocument::createFromString('<p id="a">b</p><p id="a">c</p>', LIBXML_NOERROR);
10+
$p = $d->getElementById('a');
11+
$p->remove();
12+
echo $d->getElementById('a')->textContent, "\n";
13+
?>
14+
--EXPECT--
15+
c

0 commit comments

Comments
 (0)