diff options
author | Benjamin Eberlei <kontakt@beberlei.de> | 2021-02-01 21:11:12 +0100 |
---|---|---|
committer | Benjamin Eberlei <kontakt@beberlei.de> | 2021-02-02 20:26:52 +0100 |
commit | 665e1f324a543bd04bcdd8dec089b82091c61671 (patch) | |
tree | faf5e1f09595b576c84cb3f61ebaf9a51aae1779 | |
parent | 37ab72768f40fd028cc39ffb247c4416835b4001 (diff) | |
download | php-git-665e1f324a543bd04bcdd8dec089b82091c61671.tar.gz |
Fix bug #80600 DOMChildNode::remove does not work on DOMCharacterData.
Closes GH-6660
-rw-r--r-- | ext/dom/characterdata.c | 36 | ||||
-rw-r--r-- | ext/dom/parentnode.c | 8 | ||||
-rw-r--r-- | ext/dom/tests/bug80600.phpt | 11 |
3 files changed, 17 insertions, 38 deletions
diff --git a/ext/dom/characterdata.c b/ext/dom/characterdata.c index b3774c3c88..cd332c8db4 100644 --- a/ext/dom/characterdata.c +++ b/ext/dom/characterdata.c @@ -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(); } diff --git a/ext/dom/parentnode.c b/ext/dom/parentnode.c index f47416edff..375c692dca 100644 --- a/ext/dom/parentnode.c +++ b/ext/dom/parentnode.c @@ -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 index 0000000000..31f679c82b --- /dev/null +++ b/ext/dom/tests/bug80600.phpt @@ -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/> |