1
0
mirror of https://github.com/php/php-src.git synced 2026-03-24 00:02:20 +01:00

Merge branch 'PHP-8.5'

* PHP-8.5:
  Fix GH-20281: \Dom\Document::getElementById() is inconsistent after nodes are removed
This commit is contained in:
Niels Dossche
2025-10-25 12:24:16 +02:00
2 changed files with 19 additions and 1 deletions

View File

@@ -268,7 +268,10 @@ static lexbor_libxml2_bridge_status lexbor_libxml2_bridge_convert(
/* xmlIsID does some other stuff too that is irrelevant here. */
if (local_name_length == 2 && local_name[0] == 'i' && local_name[1] == 'd' && attr->node.ns == LXB_NS_HTML) {
xmlAddID(NULL, lxml_doc, value, lxml_attr);
if (xmlAddID(NULL, lxml_doc, value, lxml_attr) == 0) {
/* If the ID already exists, the ID attribute still needs to be marked as an ID. */
lxml_attr->atype = XML_ATTRIBUTE_ID;
}
}
/* libxml2 doesn't support line numbers on this anyway, it derives them instead, so don't bother */

View File

@@ -0,0 +1,15 @@
--TEST--
GH-20281 (\Dom\Document::getElementById() is inconsistent after nodes are removed)
--EXTENSIONS--
dom
--CREDITS--
cscott
--FILE--
<?php
$d = \Dom\HTMLDocument::createFromString('<p id="a">b</p><p id="a">c</p>', LIBXML_NOERROR);
$p = $d->getElementById('a');
$p->remove();
echo $d->getElementById('a')->textContent, "\n";
?>
--EXPECT--
c