Commit 60b650842f7 for php
commit 60b650842f78d15d6a3ee9af47bf98ac111f2f40
Merge: 661a5d81a8f 3d70ccea513
Author: David Carlier <devnexen@gmail.com>
Date: Sun Dec 6 20:20:19 2026 +0000
Merge branch 'PHP-8.5' into PHP-8.6
* PHP-8.5:
ext/dom: insertAdjacentElement() crash when inserting the element itself
# Conflicts:
# ext/dom/element.c
diff --cc ext/dom/element.c
index 1da2b377cb5,5e11a7fb3a8..3bd27029766
--- a/ext/dom/element.c
+++ b/ext/dom/element.c
@@@ -1622,10 -1637,22 +1622,23 @@@ PHP_METHOD(DOMElement, replaceChildren
#define INSERT_ADJACENT_RES_SYNTAX_FAILED INSERT_ADJACENT_RES_ADOPT_FAILED
#define INSERT_ADJACENT_RES_PRE_INSERT_FAILED ((void*) -2)
+ static bool dom_insert_adjacent_adopt(xmlNodePtr otherp, dom_object *this_intern, xmlNodePtr thisp, xmlNodePtr parent, xmlNodePtr insertion_point)
+ {
+ if (otherp->doc == thisp->doc) {
+ /* php_dom_pre_insert() unlinks the node, but only after validating. */
+ php_libxml_invalidate_node_list_cache_from_doc(otherp->doc);
+ return true;
+ }
+ if (!php_dom_pre_insert_is_valid_before_adopt(this_intern->document, otherp, parent, insertion_point)) {
+ return false;
+ }
+ return php_dom_adopt_node(otherp, this_intern, thisp->doc);
+ }
+
-static xmlNodePtr dom_insert_adjacent(const zend_string *where, xmlNodePtr thisp, dom_object *this_intern, xmlNodePtr otherp)
+static xmlNodePtr dom_insert_adjacent(zend_enum_Dom_AdjacentPosition where, xmlNodePtr thisp, dom_object *this_intern, xmlNodePtr otherp)
{
- if (zend_string_equals_literal_ci(where, "beforebegin")) {
+ switch (where) {
+ case ZEND_ENUM_Dom_AdjacentPosition_BeforeBegin:
if (thisp->parent == NULL) {
return NULL;
}
@@@ -1635,17 -1662,15 +1648,17 @@@
if (!php_dom_pre_insert(this_intern->document, otherp, thisp->parent, thisp)) {
return INSERT_ADJACENT_RES_PRE_INSERT_FAILED;
}
- } else if (zend_string_equals_literal_ci(where, "afterbegin")) {
+ break;
+ case ZEND_ENUM_Dom_AdjacentPosition_AfterBegin:
- if (!php_dom_adopt_node(otherp, this_intern, thisp->doc)) {
+ if (!dom_insert_adjacent_adopt(otherp, this_intern, thisp, thisp, thisp->children)) {
return INSERT_ADJACENT_RES_ADOPT_FAILED;
}
if (!php_dom_pre_insert(this_intern->document, otherp, thisp, thisp->children)) {
return INSERT_ADJACENT_RES_PRE_INSERT_FAILED;
}
- } else if (zend_string_equals_literal_ci(where, "beforeend")) {
+ break;
+ case ZEND_ENUM_Dom_AdjacentPosition_BeforeEnd:
- if (!php_dom_adopt_node(otherp, this_intern, thisp->doc)) {
+ if (!dom_insert_adjacent_adopt(otherp, this_intern, thisp, thisp, NULL)) {
return INSERT_ADJACENT_RES_ADOPT_FAILED;
}
if (!php_dom_pre_insert(this_intern->document, otherp, thisp, NULL)) {