mirror of
https://github.com/php/php-src.git
synced 2025-08-16 05:58:45 +02:00
Fix arginfo violation in removeChild() (#14717)
It was possible to return false without throwing an exception. This is even wrong in "old DOM" because we expect either a NOT_FOUND_ERR or NO_MODIFICATION_ALLOWED_ERR according to the documentation. A side effect of this patch is that it prioritises NOT_FOUND_ERR over NO_MODIFICATION_ALLOWED_ERR but I think that's fine.
This commit is contained in:
parent
de8b13fde2
commit
c66221b7ba
2 changed files with 25 additions and 9 deletions
|
@ -1229,22 +1229,18 @@ static void dom_node_remove_child(INTERNAL_FUNCTION_PARAMETERS, zend_class_entry
|
||||||
|
|
||||||
DOM_GET_OBJ(nodep, ZEND_THIS, xmlNodePtr, intern);
|
DOM_GET_OBJ(nodep, ZEND_THIS, xmlNodePtr, intern);
|
||||||
|
|
||||||
if (!dom_node_children_valid(nodep)) {
|
|
||||||
RETURN_FALSE;
|
|
||||||
}
|
|
||||||
|
|
||||||
DOM_GET_OBJ(child, node, xmlNodePtr, childobj);
|
DOM_GET_OBJ(child, node, xmlNodePtr, childobj);
|
||||||
|
|
||||||
bool stricterror = dom_get_strict_error(intern->document);
|
bool stricterror = dom_get_strict_error(intern->document);
|
||||||
|
|
||||||
if (dom_node_is_read_only(nodep) == SUCCESS ||
|
if (!nodep->children || child->parent != nodep) {
|
||||||
(child->parent != NULL && dom_node_is_read_only(child->parent) == SUCCESS)) {
|
php_dom_throw_error(NOT_FOUND_ERR, stricterror);
|
||||||
php_dom_throw_error(NO_MODIFICATION_ALLOWED_ERR, stricterror);
|
|
||||||
RETURN_FALSE;
|
RETURN_FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!nodep->children || child->parent != nodep) {
|
if (dom_node_is_read_only(nodep) == SUCCESS ||
|
||||||
php_dom_throw_error(NOT_FOUND_ERR, stricterror);
|
(child->parent != NULL && dom_node_is_read_only(child->parent) == SUCCESS)) {
|
||||||
|
php_dom_throw_error(NO_MODIFICATION_ALLOWED_ERR, stricterror);
|
||||||
RETURN_FALSE;
|
RETURN_FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
20
ext/dom/tests/modern/xml/Node_removeChild_from_comment.phpt
Normal file
20
ext/dom/tests/modern/xml/Node_removeChild_from_comment.phpt
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
--TEST--
|
||||||
|
Removing a child from a comment should result in NOT_FOUND_ERR
|
||||||
|
--EXTENSIONS--
|
||||||
|
dom
|
||||||
|
--FILE--
|
||||||
|
<?php
|
||||||
|
|
||||||
|
$dom = Dom\XMLDocument::createFromString('<root><!-- comment --><child/></root>');
|
||||||
|
$comment = $dom->documentElement->firstChild;
|
||||||
|
$child = $comment->nextSibling;
|
||||||
|
|
||||||
|
try {
|
||||||
|
$comment->removeChild($child);
|
||||||
|
} catch (DOMException $e) {
|
||||||
|
echo $e->getMessage(), "\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
?>
|
||||||
|
--EXPECT--
|
||||||
|
Not Found Error
|
Loading…
Add table
Add a link
Reference in a new issue