]> granicus.if.org Git - php/commitdiff
Fix bug #80600 DOMChildNode::remove does not work on DOMCharacterData.
authorBenjamin Eberlei <kontakt@beberlei.de>
Mon, 1 Feb 2021 20:11:12 +0000 (21:11 +0100)
committerBenjamin Eberlei <kontakt@beberlei.de>
Tue, 2 Feb 2021 19:26:52 +0000 (20:26 +0100)
Closes GH-6660

ext/dom/characterdata.c
ext/dom/parentnode.c
ext/dom/tests/bug80600.phpt [new file with mode: 0644]

index b3774c3c88e7f17c43d4bce01a202e72d95a233d..cd332c8db4cd9b721fce765c11e05156517fdccb 100644 (file)
@@ -349,9 +349,8 @@ PHP_METHOD(DOMCharacterData, replaceData)
 PHP_METHOD(DOMCharacterData, remove)
 {
        zval *id = ZEND_THIS;
-       xmlNodePtr children, child;
+       xmlNodePtr child;
        dom_object *intern;
-       int stricterror;
 
        if (zend_parse_parameters_none() == FAILURE) {
                RETURN_THROWS();
@@ -359,38 +358,7 @@ PHP_METHOD(DOMCharacterData, remove)
 
        DOM_GET_OBJ(child, id, xmlNodePtr, intern);
 
-       if (dom_node_children_valid(child) == FAILURE) {
-               RETURN_NULL();
-       }
-
-       stricterror = dom_get_strict_error(intern->document);
-
-       if (dom_node_is_read_only(child) == SUCCESS ||
-               (child->parent != NULL && dom_node_is_read_only(child->parent) == SUCCESS)) {
-               php_dom_throw_error(NO_MODIFICATION_ALLOWED_ERR, stricterror);
-               RETURN_NULL();
-       }
-
-       if (!child->parent) {
-               php_dom_throw_error(NOT_FOUND_ERR, stricterror);
-               RETURN_NULL();
-       }
-
-       children = child->parent->children;
-       if (!children) {
-               php_dom_throw_error(NOT_FOUND_ERR, stricterror);
-               RETURN_NULL();
-       }
-
-       while (children) {
-               if (children == child) {
-                       xmlUnlinkNode(child);
-                       RETURN_NULL();
-               }
-               children = children->next;
-       }
-
-       php_dom_throw_error(NOT_FOUND_ERR, stricterror);
+       dom_child_node_remove(intern);
        RETURN_NULL();
 }
 
index f47416edff3dd9fb666a0f46197ee2b3e097a033..375c692dcad85805b7fc5fd153feb988fa4b3614 100644 (file)
@@ -374,10 +374,6 @@ void dom_child_node_remove(dom_object *context)
        xmlNodePtr children;
        int stricterror;
 
-       if (dom_node_children_valid(child) == FAILURE) {
-               return;
-       }
-
        stricterror = dom_get_strict_error(context->document);
 
        if (dom_node_is_read_only(child) == SUCCESS ||
@@ -391,6 +387,10 @@ void dom_child_node_remove(dom_object *context)
                return;
        }
 
+       if (dom_node_children_valid(child->parent) == FAILURE) {
+               return;
+       }
+
        children = child->parent->children;
        if (!children) {
                php_dom_throw_error(NOT_FOUND_ERR, stricterror);
diff --git a/ext/dom/tests/bug80600.phpt b/ext/dom/tests/bug80600.phpt
new file mode 100644 (file)
index 0000000..31f679c
--- /dev/null
@@ -0,0 +1,11 @@
+--TEST--
+dom: DOMChildNode::remove does not work on character data
+--FILE--
+<?php
+
+$doc = new \DOMDocument();
+$doc->loadXML('<a><!-- foo --></a>');
+$doc->documentElement->firstChild->remove();
+echo $doc->saveXML($doc->documentElement);
+--EXPECTF--
+<a/>