mirror of
https://github.com/php/php-src.git
synced 2025-08-16 05:58:45 +02:00
Merge branch 'PHP-8.1' into PHP-8.2
* PHP-8.1: Fix GH-11830: ParentNode methods should perform their checks upfront Fix manually calling __construct() on DOM classes
This commit is contained in:
commit
b80ded8303
25 changed files with 642 additions and 124 deletions
3
NEWS
3
NEWS
|
@ -17,6 +17,9 @@ PHP NEWS
|
||||||
. Fixed bug GH-11791 (Wrong default value of DOMDocument::xmlStandalone).
|
. Fixed bug GH-11791 (Wrong default value of DOMDocument::xmlStandalone).
|
||||||
(nielsdos)
|
(nielsdos)
|
||||||
. Fix json_encode result on DOMDocument. (nielsdos)
|
. Fix json_encode result on DOMDocument. (nielsdos)
|
||||||
|
. Fix manually calling __construct() on DOM classes. (nielsdos)
|
||||||
|
. Fixed bug GH-11830 (ParentNode methods should perform their checks
|
||||||
|
upfront). (nielsdos)
|
||||||
|
|
||||||
- FFI:
|
- FFI:
|
||||||
. Fix leaking definitions when using FFI::cdef()->new(...). (ilutov)
|
. Fix leaking definitions when using FFI::cdef()->new(...). (ilutov)
|
||||||
|
|
|
@ -62,7 +62,7 @@ PHP_METHOD(DOMAttr, __construct)
|
||||||
|
|
||||||
oldnode = dom_object_get_node(intern);
|
oldnode = dom_object_get_node(intern);
|
||||||
if (oldnode != NULL) {
|
if (oldnode != NULL) {
|
||||||
php_libxml_node_free_resource(oldnode );
|
php_libxml_node_decrement_resource((php_libxml_node_object *)intern);
|
||||||
}
|
}
|
||||||
php_libxml_increment_node_ptr((php_libxml_node_object *)intern, (xmlNodePtr)nodep, (void *)intern);
|
php_libxml_increment_node_ptr((php_libxml_node_object *)intern, (xmlNodePtr)nodep, (void *)intern);
|
||||||
}
|
}
|
||||||
|
|
|
@ -52,7 +52,7 @@ PHP_METHOD(DOMCdataSection, __construct)
|
||||||
intern = Z_DOMOBJ_P(ZEND_THIS);
|
intern = Z_DOMOBJ_P(ZEND_THIS);
|
||||||
oldnode = dom_object_get_node(intern);
|
oldnode = dom_object_get_node(intern);
|
||||||
if (oldnode != NULL) {
|
if (oldnode != NULL) {
|
||||||
php_libxml_node_free_resource(oldnode );
|
php_libxml_node_decrement_resource((php_libxml_node_object *)intern);
|
||||||
}
|
}
|
||||||
php_libxml_increment_node_ptr((php_libxml_node_object *)intern, nodep, (void *)intern);
|
php_libxml_increment_node_ptr((php_libxml_node_object *)intern, nodep, (void *)intern);
|
||||||
}
|
}
|
||||||
|
|
|
@ -50,13 +50,11 @@ PHP_METHOD(DOMComment, __construct)
|
||||||
}
|
}
|
||||||
|
|
||||||
intern = Z_DOMOBJ_P(ZEND_THIS);
|
intern = Z_DOMOBJ_P(ZEND_THIS);
|
||||||
if (intern != NULL) {
|
oldnode = dom_object_get_node(intern);
|
||||||
oldnode = dom_object_get_node(intern);
|
if (oldnode != NULL) {
|
||||||
if (oldnode != NULL) {
|
php_libxml_node_decrement_resource((php_libxml_node_object *)intern);
|
||||||
php_libxml_node_free_resource(oldnode );
|
|
||||||
}
|
|
||||||
php_libxml_increment_node_ptr((php_libxml_node_object *)intern, (xmlNodePtr)nodep, (void *)intern);
|
|
||||||
}
|
}
|
||||||
|
php_libxml_increment_node_ptr((php_libxml_node_object *)intern, (xmlNodePtr)nodep, (void *)intern);
|
||||||
}
|
}
|
||||||
/* }}} end DOMComment::__construct */
|
/* }}} end DOMComment::__construct */
|
||||||
|
|
||||||
|
|
|
@ -1118,22 +1118,20 @@ PHP_METHOD(DOMDocument, __construct)
|
||||||
}
|
}
|
||||||
|
|
||||||
intern = Z_DOMOBJ_P(ZEND_THIS);
|
intern = Z_DOMOBJ_P(ZEND_THIS);
|
||||||
if (intern != NULL) {
|
olddoc = (xmlDocPtr) dom_object_get_node(intern);
|
||||||
olddoc = (xmlDocPtr) dom_object_get_node(intern);
|
if (olddoc != NULL) {
|
||||||
if (olddoc != NULL) {
|
php_libxml_decrement_node_ptr((php_libxml_node_object *) intern);
|
||||||
php_libxml_decrement_node_ptr((php_libxml_node_object *) intern);
|
refcount = php_libxml_decrement_doc_ref((php_libxml_node_object *)intern);
|
||||||
refcount = php_libxml_decrement_doc_ref((php_libxml_node_object *)intern);
|
if (refcount != 0) {
|
||||||
if (refcount != 0) {
|
olddoc->_private = NULL;
|
||||||
olddoc->_private = NULL;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
intern->document = NULL;
|
|
||||||
if (php_libxml_increment_doc_ref((php_libxml_node_object *)intern, docp) == -1) {
|
|
||||||
/* docp is always non-null so php_libxml_increment_doc_ref() never returns -1 */
|
|
||||||
ZEND_UNREACHABLE();
|
|
||||||
}
|
|
||||||
php_libxml_increment_node_ptr((php_libxml_node_object *)intern, (xmlNodePtr)docp, (void *)intern);
|
|
||||||
}
|
}
|
||||||
|
intern->document = NULL;
|
||||||
|
if (php_libxml_increment_doc_ref((php_libxml_node_object *)intern, docp) == -1) {
|
||||||
|
/* docp is always non-null so php_libxml_increment_doc_ref() never returns -1 */
|
||||||
|
ZEND_UNREACHABLE();
|
||||||
|
}
|
||||||
|
php_libxml_increment_node_ptr((php_libxml_node_object *)intern, (xmlNodePtr)docp, (void *)intern);
|
||||||
}
|
}
|
||||||
/* }}} end DOMDocument::__construct */
|
/* }}} end DOMDocument::__construct */
|
||||||
|
|
||||||
|
|
|
@ -50,9 +50,8 @@ PHP_METHOD(DOMDocumentFragment, __construct)
|
||||||
intern = Z_DOMOBJ_P(ZEND_THIS);
|
intern = Z_DOMOBJ_P(ZEND_THIS);
|
||||||
oldnode = dom_object_get_node(intern);
|
oldnode = dom_object_get_node(intern);
|
||||||
if (oldnode != NULL) {
|
if (oldnode != NULL) {
|
||||||
php_libxml_node_free_resource(oldnode );
|
php_libxml_node_decrement_resource((php_libxml_node_object *)intern);
|
||||||
}
|
}
|
||||||
/* php_dom_set_object(intern, nodep); */
|
|
||||||
php_libxml_increment_node_ptr((php_libxml_node_object *)intern, nodep, (void *)intern);
|
php_libxml_increment_node_ptr((php_libxml_node_object *)intern, nodep, (void *)intern);
|
||||||
}
|
}
|
||||||
/* }}} end DOMDocumentFragment::__construct */
|
/* }}} end DOMDocumentFragment::__construct */
|
||||||
|
|
|
@ -97,7 +97,7 @@ PHP_METHOD(DOMElement, __construct)
|
||||||
intern = Z_DOMOBJ_P(ZEND_THIS);
|
intern = Z_DOMOBJ_P(ZEND_THIS);
|
||||||
oldnode = dom_object_get_node(intern);
|
oldnode = dom_object_get_node(intern);
|
||||||
if (oldnode != NULL) {
|
if (oldnode != NULL) {
|
||||||
php_libxml_node_free_resource(oldnode );
|
php_libxml_node_decrement_resource((php_libxml_node_object *)intern);
|
||||||
}
|
}
|
||||||
php_libxml_increment_node_ptr((php_libxml_node_object *)intern, nodep, (void *)intern);
|
php_libxml_increment_node_ptr((php_libxml_node_object *)intern, nodep, (void *)intern);
|
||||||
}
|
}
|
||||||
|
|
|
@ -57,13 +57,11 @@ PHP_METHOD(DOMEntityReference, __construct)
|
||||||
}
|
}
|
||||||
|
|
||||||
intern = Z_DOMOBJ_P(ZEND_THIS);
|
intern = Z_DOMOBJ_P(ZEND_THIS);
|
||||||
if (intern != NULL) {
|
oldnode = dom_object_get_node(intern);
|
||||||
oldnode = dom_object_get_node(intern);
|
if (oldnode != NULL) {
|
||||||
if (oldnode != NULL) {
|
php_libxml_node_decrement_resource((php_libxml_node_object *)intern);
|
||||||
php_libxml_node_free_resource(oldnode );
|
|
||||||
}
|
|
||||||
php_libxml_increment_node_ptr((php_libxml_node_object *)intern, node, (void *)intern);
|
|
||||||
}
|
}
|
||||||
|
php_libxml_increment_node_ptr((php_libxml_node_object *)intern, node, (void *)intern);
|
||||||
}
|
}
|
||||||
/* }}} end DOMEntityReference::__construct */
|
/* }}} end DOMEntityReference::__construct */
|
||||||
|
|
||||||
|
|
|
@ -141,26 +141,24 @@ static bool dom_is_node_in_list(const zval *nodes, int nodesc, const xmlNodePtr
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static xmlDocPtr dom_doc_from_context_node(xmlNodePtr contextNode)
|
||||||
|
{
|
||||||
|
if (contextNode->type == XML_DOCUMENT_NODE || contextNode->type == XML_HTML_DOCUMENT_NODE) {
|
||||||
|
return (xmlDocPtr) contextNode;
|
||||||
|
} else {
|
||||||
|
return contextNode->doc;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
xmlNode* dom_zvals_to_fragment(php_libxml_ref_obj *document, xmlNode *contextNode, zval *nodes, int nodesc)
|
xmlNode* dom_zvals_to_fragment(php_libxml_ref_obj *document, xmlNode *contextNode, zval *nodes, int nodesc)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
xmlDoc *documentNode;
|
xmlDoc *documentNode;
|
||||||
xmlNode *fragment;
|
xmlNode *fragment;
|
||||||
xmlNode *newNode;
|
xmlNode *newNode;
|
||||||
zend_class_entry *ce;
|
|
||||||
dom_object *newNodeObj;
|
dom_object *newNodeObj;
|
||||||
int stricterror;
|
|
||||||
|
|
||||||
if (document == NULL) {
|
documentNode = dom_doc_from_context_node(contextNode);
|
||||||
php_dom_throw_error(HIERARCHY_REQUEST_ERR, 1);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (contextNode->type == XML_DOCUMENT_NODE || contextNode->type == XML_HTML_DOCUMENT_NODE) {
|
|
||||||
documentNode = (xmlDoc *) contextNode;
|
|
||||||
} else {
|
|
||||||
documentNode = contextNode->doc;
|
|
||||||
}
|
|
||||||
|
|
||||||
fragment = xmlNewDocFragment(documentNode);
|
fragment = xmlNewDocFragment(documentNode);
|
||||||
|
|
||||||
|
@ -168,80 +166,59 @@ xmlNode* dom_zvals_to_fragment(php_libxml_ref_obj *document, xmlNode *contextNod
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
stricterror = dom_get_strict_error(document);
|
|
||||||
|
|
||||||
for (i = 0; i < nodesc; i++) {
|
for (i = 0; i < nodesc; i++) {
|
||||||
if (Z_TYPE(nodes[i]) == IS_OBJECT) {
|
if (Z_TYPE(nodes[i]) == IS_OBJECT) {
|
||||||
ce = Z_OBJCE(nodes[i]);
|
newNodeObj = Z_DOMOBJ_P(&nodes[i]);
|
||||||
|
newNode = dom_object_get_node(newNodeObj);
|
||||||
|
|
||||||
if (instanceof_function(ce, dom_node_class_entry)) {
|
if (newNode->parent != NULL) {
|
||||||
newNodeObj = Z_DOMOBJ_P(&nodes[i]);
|
xmlUnlinkNode(newNode);
|
||||||
newNode = dom_object_get_node(newNodeObj);
|
}
|
||||||
|
|
||||||
if (newNode->doc != documentNode) {
|
newNodeObj->document = document;
|
||||||
php_dom_throw_error(WRONG_DOCUMENT_ERR, stricterror);
|
xmlSetTreeDoc(newNode, documentNode);
|
||||||
goto err;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (newNode->parent != NULL) {
|
/* Citing from the docs (https://gnome.pages.gitlab.gnome.org/libxml2/devhelp/libxml2-tree.html#xmlAddChild):
|
||||||
|
* "Add a new node to @parent, at the end of the child (or property) list merging adjacent TEXT nodes (in which case @cur is freed)".
|
||||||
|
* So we must take a copy if this situation arises to prevent a use-after-free. */
|
||||||
|
bool will_free = newNode->type == XML_TEXT_NODE && fragment->last && fragment->last->type == XML_TEXT_NODE;
|
||||||
|
if (will_free) {
|
||||||
|
newNode = xmlCopyNode(newNode, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (newNode->type == XML_DOCUMENT_FRAG_NODE) {
|
||||||
|
/* Unpack document fragment nodes, the behaviour differs for different libxml2 versions. */
|
||||||
|
newNode = newNode->children;
|
||||||
|
while (newNode) {
|
||||||
|
xmlNodePtr next = newNode->next;
|
||||||
xmlUnlinkNode(newNode);
|
xmlUnlinkNode(newNode);
|
||||||
|
if (!xmlAddChild(fragment, newNode)) {
|
||||||
|
goto err;
|
||||||
|
}
|
||||||
|
newNode = next;
|
||||||
}
|
}
|
||||||
|
} else if (!xmlAddChild(fragment, newNode)) {
|
||||||
newNodeObj->document = document;
|
|
||||||
xmlSetTreeDoc(newNode, documentNode);
|
|
||||||
|
|
||||||
if (newNode->type == XML_ATTRIBUTE_NODE) {
|
|
||||||
goto hierarchy_request_err;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Citing from the docs (https://gnome.pages.gitlab.gnome.org/libxml2/devhelp/libxml2-tree.html#xmlAddChild):
|
|
||||||
* "Add a new node to @parent, at the end of the child (or property) list merging adjacent TEXT nodes (in which case @cur is freed)".
|
|
||||||
* So we must take a copy if this situation arises to prevent a use-after-free. */
|
|
||||||
bool will_free = newNode->type == XML_TEXT_NODE && fragment->last && fragment->last->type == XML_TEXT_NODE;
|
|
||||||
if (will_free) {
|
if (will_free) {
|
||||||
newNode = xmlCopyNode(newNode, 1);
|
xmlFreeNode(newNode);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (newNode->type == XML_DOCUMENT_FRAG_NODE) {
|
|
||||||
/* Unpack document fragment nodes, the behaviour differs for different libxml2 versions. */
|
|
||||||
newNode = newNode->children;
|
|
||||||
while (newNode) {
|
|
||||||
xmlNodePtr next = newNode->next;
|
|
||||||
xmlUnlinkNode(newNode);
|
|
||||||
if (!xmlAddChild(fragment, newNode)) {
|
|
||||||
goto hierarchy_request_err;
|
|
||||||
}
|
|
||||||
newNode = next;
|
|
||||||
}
|
|
||||||
} else if (!xmlAddChild(fragment, newNode)) {
|
|
||||||
if (will_free) {
|
|
||||||
xmlFreeNode(newNode);
|
|
||||||
}
|
|
||||||
goto hierarchy_request_err;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
zend_argument_type_error(i + 1, "must be of type DOMNode|string, %s given", zend_zval_type_name(&nodes[i]));
|
|
||||||
goto err;
|
goto err;
|
||||||
}
|
}
|
||||||
} else if (Z_TYPE(nodes[i]) == IS_STRING) {
|
} else {
|
||||||
|
ZEND_ASSERT(Z_TYPE(nodes[i]) == IS_STRING);
|
||||||
|
|
||||||
newNode = xmlNewDocText(documentNode, (xmlChar *) Z_STRVAL(nodes[i]));
|
newNode = xmlNewDocText(documentNode, (xmlChar *) Z_STRVAL(nodes[i]));
|
||||||
|
|
||||||
xmlSetTreeDoc(newNode, documentNode);
|
xmlSetTreeDoc(newNode, documentNode);
|
||||||
|
|
||||||
if (!xmlAddChild(fragment, newNode)) {
|
if (!xmlAddChild(fragment, newNode)) {
|
||||||
xmlFreeNode(newNode);
|
xmlFreeNode(newNode);
|
||||||
goto hierarchy_request_err;
|
goto err;
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
zend_argument_type_error(i + 1, "must be of type DOMNode|string, %s given", zend_zval_type_name(&nodes[i]));
|
|
||||||
goto err;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return fragment;
|
return fragment;
|
||||||
|
|
||||||
hierarchy_request_err:
|
|
||||||
php_dom_throw_error(HIERARCHY_REQUEST_ERR, stricterror);
|
|
||||||
err:
|
err:
|
||||||
xmlFreeNode(fragment);
|
xmlFreeNode(fragment);
|
||||||
return NULL;
|
return NULL;
|
||||||
|
@ -264,17 +241,39 @@ static void dom_fragment_assign_parent_node(xmlNodePtr parentNode, xmlNodePtr fr
|
||||||
fragment->last = NULL;
|
fragment->last = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
static zend_result dom_hierarchy_node_list(xmlNodePtr parentNode, zval *nodes, int nodesc)
|
static zend_result dom_sanity_check_node_list_for_insertion(php_libxml_ref_obj *document, xmlNodePtr parentNode, zval *nodes, int nodesc)
|
||||||
{
|
{
|
||||||
|
if (document == NULL) {
|
||||||
|
php_dom_throw_error(HIERARCHY_REQUEST_ERR, 1);
|
||||||
|
return FAILURE;
|
||||||
|
}
|
||||||
|
|
||||||
|
xmlDocPtr documentNode = dom_doc_from_context_node(parentNode);
|
||||||
|
|
||||||
for (int i = 0; i < nodesc; i++) {
|
for (int i = 0; i < nodesc; i++) {
|
||||||
if (Z_TYPE(nodes[i]) == IS_OBJECT) {
|
zend_uchar type = Z_TYPE(nodes[i]);
|
||||||
|
if (type == IS_OBJECT) {
|
||||||
const zend_class_entry *ce = Z_OBJCE(nodes[i]);
|
const zend_class_entry *ce = Z_OBJCE(nodes[i]);
|
||||||
|
|
||||||
if (instanceof_function(ce, dom_node_class_entry)) {
|
if (instanceof_function(ce, dom_node_class_entry)) {
|
||||||
if (dom_hierarchy(parentNode, dom_object_get_node(Z_DOMOBJ_P(nodes + i))) != SUCCESS) {
|
xmlNodePtr node = dom_object_get_node(Z_DOMOBJ_P(nodes + i));
|
||||||
|
|
||||||
|
if (node->doc != documentNode) {
|
||||||
|
php_dom_throw_error(WRONG_DOCUMENT_ERR, dom_get_strict_error(document));
|
||||||
return FAILURE;
|
return FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (node->type == XML_ATTRIBUTE_NODE || dom_hierarchy(parentNode, node) != SUCCESS) {
|
||||||
|
php_dom_throw_error(HIERARCHY_REQUEST_ERR, dom_get_strict_error(document));
|
||||||
|
return FAILURE;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
zend_argument_type_error(i + 1, "must be of type DOMNode|string, %s given", zend_zval_type_name(&nodes[i]));
|
||||||
|
return FAILURE;
|
||||||
}
|
}
|
||||||
|
} else if (type != IS_STRING) {
|
||||||
|
zend_argument_type_error(i + 1, "must be of type DOMNode|string, %s given", zend_zval_type_name(&nodes[i]));
|
||||||
|
return FAILURE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -286,8 +285,7 @@ void dom_parent_node_append(dom_object *context, zval *nodes, int nodesc)
|
||||||
xmlNode *parentNode = dom_object_get_node(context);
|
xmlNode *parentNode = dom_object_get_node(context);
|
||||||
xmlNodePtr newchild, prevsib;
|
xmlNodePtr newchild, prevsib;
|
||||||
|
|
||||||
if (UNEXPECTED(dom_hierarchy_node_list(parentNode, nodes, nodesc) != SUCCESS)) {
|
if (UNEXPECTED(dom_sanity_check_node_list_for_insertion(context->document, parentNode, nodes, nodesc) != SUCCESS)) {
|
||||||
php_dom_throw_error(HIERARCHY_REQUEST_ERR, dom_get_strict_error(context->document));
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -329,8 +327,7 @@ void dom_parent_node_prepend(dom_object *context, zval *nodes, int nodesc)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (UNEXPECTED(dom_hierarchy_node_list(parentNode, nodes, nodesc) != SUCCESS)) {
|
if (UNEXPECTED(dom_sanity_check_node_list_for_insertion(context->document, parentNode, nodes, nodesc) != SUCCESS)) {
|
||||||
php_dom_throw_error(HIERARCHY_REQUEST_ERR, dom_get_strict_error(context->document));
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -414,6 +411,10 @@ void dom_parent_node_after(dom_object *context, zval *nodes, int nodesc)
|
||||||
|
|
||||||
doc = prevsib->doc;
|
doc = prevsib->doc;
|
||||||
|
|
||||||
|
if (UNEXPECTED(dom_sanity_check_node_list_for_insertion(context->document, parentNode, nodes, nodesc) != SUCCESS)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
/* Spec step 4: convert nodes into fragment */
|
/* Spec step 4: convert nodes into fragment */
|
||||||
fragment = dom_zvals_to_fragment(context->document, parentNode, nodes, nodesc);
|
fragment = dom_zvals_to_fragment(context->document, parentNode, nodes, nodesc);
|
||||||
|
|
||||||
|
@ -465,6 +466,10 @@ void dom_parent_node_before(dom_object *context, zval *nodes, int nodesc)
|
||||||
|
|
||||||
doc = nextsib->doc;
|
doc = nextsib->doc;
|
||||||
|
|
||||||
|
if (UNEXPECTED(dom_sanity_check_node_list_for_insertion(context->document, parentNode, nodes, nodesc) != SUCCESS)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
/* Spec step 4: convert nodes into fragment */
|
/* Spec step 4: convert nodes into fragment */
|
||||||
fragment = dom_zvals_to_fragment(context->document, parentNode, nodes, nodesc);
|
fragment = dom_zvals_to_fragment(context->document, parentNode, nodes, nodesc);
|
||||||
|
|
||||||
|
@ -555,6 +560,10 @@ void dom_child_replace_with(dom_object *context, zval *nodes, int nodesc)
|
||||||
|
|
||||||
xmlNodePtr insertion_point = child->next;
|
xmlNodePtr insertion_point = child->next;
|
||||||
|
|
||||||
|
if (UNEXPECTED(dom_sanity_check_node_list_for_insertion(context->document, parentNode, nodes, nodesc) != SUCCESS)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
xmlNodePtr fragment = dom_zvals_to_fragment(context->document, parentNode, nodes, nodesc);
|
xmlNodePtr fragment = dom_zvals_to_fragment(context->document, parentNode, nodes, nodesc);
|
||||||
if (UNEXPECTED(fragment == NULL)) {
|
if (UNEXPECTED(fragment == NULL)) {
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -59,7 +59,7 @@ PHP_METHOD(DOMProcessingInstruction, __construct)
|
||||||
intern = Z_DOMOBJ_P(ZEND_THIS);
|
intern = Z_DOMOBJ_P(ZEND_THIS);
|
||||||
oldnode = dom_object_get_node(intern);
|
oldnode = dom_object_get_node(intern);
|
||||||
if (oldnode != NULL) {
|
if (oldnode != NULL) {
|
||||||
php_libxml_node_free_resource(oldnode );
|
php_libxml_node_decrement_resource((php_libxml_node_object *)intern);
|
||||||
}
|
}
|
||||||
php_libxml_increment_node_ptr((php_libxml_node_object *)intern, nodep, (void *)intern);
|
php_libxml_increment_node_ptr((php_libxml_node_object *)intern, nodep, (void *)intern);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,16 +0,0 @@
|
||||||
--TEST--
|
|
||||||
DOMDocumentFragment::__construct() called twice.
|
|
||||||
--CREDITS--
|
|
||||||
Eric Lee Stewart <ericleestewart@gmail.com>
|
|
||||||
# TestFest Atlanta 2009-05-24
|
|
||||||
--EXTENSIONS--
|
|
||||||
dom
|
|
||||||
--FILE--
|
|
||||||
<?php
|
|
||||||
$fragment = new DOMDocumentFragment();
|
|
||||||
$fragment->__construct();
|
|
||||||
var_dump($fragment);
|
|
||||||
?>
|
|
||||||
--EXPECT--
|
|
||||||
object(DOMDocumentFragment)#1 (0) {
|
|
||||||
}
|
|
56
ext/dom/tests/gh11830/attribute_variation.phpt
Normal file
56
ext/dom/tests/gh11830/attribute_variation.phpt
Normal file
|
@ -0,0 +1,56 @@
|
||||||
|
--TEST--
|
||||||
|
GH-11830 (ParentNode methods should perform their checks upfront) - attribute variation
|
||||||
|
--EXTENSIONS--
|
||||||
|
dom
|
||||||
|
--FILE--
|
||||||
|
<?php
|
||||||
|
$doc = new DOMDocument;
|
||||||
|
$doc->loadXML(<<<XML
|
||||||
|
<?xml version="1.0"?>
|
||||||
|
<container x="foo">
|
||||||
|
<test/>
|
||||||
|
</container>
|
||||||
|
XML);
|
||||||
|
|
||||||
|
try {
|
||||||
|
$doc->documentElement->firstElementChild->prepend($doc->documentElement->attributes[0]);
|
||||||
|
} catch (\DOMException $e) {
|
||||||
|
echo $e->getMessage(), "\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
$doc->documentElement->firstElementChild->append($doc->documentElement->attributes[0]);
|
||||||
|
} catch (\DOMException $e) {
|
||||||
|
echo $e->getMessage(), "\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
$doc->documentElement->firstElementChild->before($doc->documentElement->attributes[0]);
|
||||||
|
} catch (\DOMException $e) {
|
||||||
|
echo $e->getMessage(), "\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
$doc->documentElement->firstElementChild->after($doc->documentElement->attributes[0]);
|
||||||
|
} catch (\DOMException $e) {
|
||||||
|
echo $e->getMessage(), "\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
$doc->documentElement->firstElementChild->replaceWith($doc->documentElement->attributes[0]);
|
||||||
|
} catch (\DOMException $e) {
|
||||||
|
echo $e->getMessage(), "\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
echo $doc->saveXML();
|
||||||
|
?>
|
||||||
|
--EXPECT--
|
||||||
|
Hierarchy Request Error
|
||||||
|
Hierarchy Request Error
|
||||||
|
Hierarchy Request Error
|
||||||
|
Hierarchy Request Error
|
||||||
|
Hierarchy Request Error
|
||||||
|
<?xml version="1.0"?>
|
||||||
|
<container x="foo">
|
||||||
|
<test/>
|
||||||
|
</container>
|
71
ext/dom/tests/gh11830/document_variation.phpt
Normal file
71
ext/dom/tests/gh11830/document_variation.phpt
Normal file
|
@ -0,0 +1,71 @@
|
||||||
|
--TEST--
|
||||||
|
GH-11830 (ParentNode methods should perform their checks upfront) - document variation
|
||||||
|
--EXTENSIONS--
|
||||||
|
dom
|
||||||
|
--FILE--
|
||||||
|
<?php
|
||||||
|
$otherDoc = new DOMDocument;
|
||||||
|
$otherDoc->loadXML(<<<XML
|
||||||
|
<?xml version="1.0"?>
|
||||||
|
<other/>
|
||||||
|
XML);
|
||||||
|
|
||||||
|
$otherElement = $otherDoc->documentElement;
|
||||||
|
|
||||||
|
$doc = new DOMDocument;
|
||||||
|
$doc->loadXML(<<<XML
|
||||||
|
<?xml version="1.0"?>
|
||||||
|
<container>
|
||||||
|
<alone/>
|
||||||
|
<child><testelement/></child>
|
||||||
|
</container>
|
||||||
|
XML);
|
||||||
|
|
||||||
|
$testElement = $doc->documentElement->firstElementChild->nextElementSibling->firstElementChild;
|
||||||
|
|
||||||
|
try {
|
||||||
|
$doc->documentElement->firstElementChild->prepend($testElement, $otherElement);
|
||||||
|
} catch (\DOMException $e) {
|
||||||
|
echo $e->getMessage(), "\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
$doc->documentElement->firstElementChild->append($testElement, $otherElement);
|
||||||
|
} catch (\DOMException $e) {
|
||||||
|
echo $e->getMessage(), "\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
$doc->documentElement->firstElementChild->before($testElement, $otherElement);
|
||||||
|
} catch (\DOMException $e) {
|
||||||
|
echo $e->getMessage(), "\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
$doc->documentElement->firstElementChild->after($testElement, $otherElement);
|
||||||
|
} catch (\DOMException $e) {
|
||||||
|
echo $e->getMessage(), "\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
$doc->documentElement->firstElementChild->replaceWith($testElement, $otherElement);
|
||||||
|
} catch (\DOMException $e) {
|
||||||
|
echo $e->getMessage(), "\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
echo $otherDoc->saveXML();
|
||||||
|
echo $doc->saveXML();
|
||||||
|
?>
|
||||||
|
--EXPECT--
|
||||||
|
Wrong Document Error
|
||||||
|
Wrong Document Error
|
||||||
|
Wrong Document Error
|
||||||
|
Wrong Document Error
|
||||||
|
Wrong Document Error
|
||||||
|
<?xml version="1.0"?>
|
||||||
|
<other/>
|
||||||
|
<?xml version="1.0"?>
|
||||||
|
<container>
|
||||||
|
<alone/>
|
||||||
|
<child><testelement/></child>
|
||||||
|
</container>
|
62
ext/dom/tests/gh11830/hierarchy_variation.phpt
Normal file
62
ext/dom/tests/gh11830/hierarchy_variation.phpt
Normal file
|
@ -0,0 +1,62 @@
|
||||||
|
--TEST--
|
||||||
|
GH-11830 (ParentNode methods should perform their checks upfront) - hierarchy variation
|
||||||
|
--EXTENSIONS--
|
||||||
|
dom
|
||||||
|
--FILE--
|
||||||
|
<?php
|
||||||
|
$doc = new DOMDocument;
|
||||||
|
$doc->loadXML(<<<XML
|
||||||
|
<?xml version="1.0"?>
|
||||||
|
<container>
|
||||||
|
<alone/>
|
||||||
|
<child><testelement/></child>
|
||||||
|
</container>
|
||||||
|
XML);
|
||||||
|
|
||||||
|
$container = $doc->documentElement;
|
||||||
|
$alone = $container->firstElementChild;
|
||||||
|
$testElement = $alone->nextElementSibling->firstElementChild;
|
||||||
|
|
||||||
|
try {
|
||||||
|
$testElement->prepend($alone, $container);
|
||||||
|
} catch (\DOMException $e) {
|
||||||
|
echo $e->getMessage(), "\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
$testElement->append($alone, $container);
|
||||||
|
} catch (\DOMException $e) {
|
||||||
|
echo $e->getMessage(), "\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
$testElement->before($alone, $container);
|
||||||
|
} catch (\DOMException $e) {
|
||||||
|
echo $e->getMessage(), "\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
$testElement->after($alone, $container);
|
||||||
|
} catch (\DOMException $e) {
|
||||||
|
echo $e->getMessage(), "\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
$testElement->replaceWith($alone, $container);
|
||||||
|
} catch (\DOMException $e) {
|
||||||
|
echo $e->getMessage(), "\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
echo $doc->saveXML();
|
||||||
|
?>
|
||||||
|
--EXPECT--
|
||||||
|
Hierarchy Request Error
|
||||||
|
Hierarchy Request Error
|
||||||
|
Hierarchy Request Error
|
||||||
|
Hierarchy Request Error
|
||||||
|
Hierarchy Request Error
|
||||||
|
<?xml version="1.0"?>
|
||||||
|
<container>
|
||||||
|
<alone/>
|
||||||
|
<child><testelement/></child>
|
||||||
|
</container>
|
60
ext/dom/tests/gh11830/type_variation.phpt
Normal file
60
ext/dom/tests/gh11830/type_variation.phpt
Normal file
|
@ -0,0 +1,60 @@
|
||||||
|
--TEST--
|
||||||
|
GH-11830 (ParentNode methods should perform their checks upfront) - type variation
|
||||||
|
--EXTENSIONS--
|
||||||
|
dom
|
||||||
|
--FILE--
|
||||||
|
<?php
|
||||||
|
$doc = new DOMDocument;
|
||||||
|
$doc->loadXML(<<<XML
|
||||||
|
<?xml version="1.0"?>
|
||||||
|
<container>
|
||||||
|
<test/>
|
||||||
|
<child><testelement/></child>
|
||||||
|
</container>
|
||||||
|
XML);
|
||||||
|
|
||||||
|
$testElement = $doc->documentElement->firstElementChild->nextElementSibling->firstElementChild;
|
||||||
|
|
||||||
|
try {
|
||||||
|
$doc->documentElement->firstElementChild->prepend($testElement, 0);
|
||||||
|
} catch (\TypeError $e) {
|
||||||
|
echo $e->getMessage(), "\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
$doc->documentElement->firstElementChild->append($testElement, true);
|
||||||
|
} catch (\TypeError $e) {
|
||||||
|
echo $e->getMessage(), "\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
$doc->documentElement->firstElementChild->before($testElement, null);
|
||||||
|
} catch (\TypeError $e) {
|
||||||
|
echo $e->getMessage(), "\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
$doc->documentElement->firstElementChild->after($testElement, new stdClass);
|
||||||
|
} catch (\TypeError $e) {
|
||||||
|
echo $e->getMessage(), "\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
$doc->documentElement->firstElementChild->replaceWith($testElement, []);
|
||||||
|
} catch (\TypeError $e) {
|
||||||
|
echo $e->getMessage(), "\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
echo $doc->saveXML();
|
||||||
|
?>
|
||||||
|
--EXPECT--
|
||||||
|
DOMElement::prepend(): Argument #2 must be of type DOMNode|string, int given
|
||||||
|
DOMElement::append(): Argument #2 must be of type DOMNode|string, bool given
|
||||||
|
DOMElement::before(): Argument #2 must be of type DOMNode|string, null given
|
||||||
|
DOMElement::after(): Argument #2 must be of type DOMNode|string, stdClass given
|
||||||
|
DOMElement::replaceWith(): Argument #2 must be of type DOMNode|string, array given
|
||||||
|
<?xml version="1.0"?>
|
||||||
|
<container>
|
||||||
|
<test/>
|
||||||
|
<child><testelement/></child>
|
||||||
|
</container>
|
34
ext/dom/tests/manually_call_constructor/attribute.phpt
Normal file
34
ext/dom/tests/manually_call_constructor/attribute.phpt
Normal file
|
@ -0,0 +1,34 @@
|
||||||
|
--TEST--
|
||||||
|
Manually call __construct() - attribute variation
|
||||||
|
--EXTENSIONS--
|
||||||
|
dom
|
||||||
|
--FILE--
|
||||||
|
<?php
|
||||||
|
|
||||||
|
$attr = new DOMAttr("attribute", "my value");
|
||||||
|
var_dump($attr->nodeName, $attr->nodeValue);
|
||||||
|
$attr->__construct("newattribute", "my new value");
|
||||||
|
var_dump($attr->nodeName, $attr->nodeValue);
|
||||||
|
|
||||||
|
$doc = new DOMDocument();
|
||||||
|
$doc->loadXML(<<<XML
|
||||||
|
<?xml version="1.0"?>
|
||||||
|
<container/>
|
||||||
|
XML);
|
||||||
|
$doc->documentElement->setAttributeNode($attr);
|
||||||
|
echo $doc->saveXML();
|
||||||
|
|
||||||
|
$attr->__construct("newnewattribute", "my even newer value");
|
||||||
|
$doc->documentElement->setAttributeNode($attr);
|
||||||
|
echo $doc->saveXML();
|
||||||
|
|
||||||
|
?>
|
||||||
|
--EXPECT--
|
||||||
|
string(9) "attribute"
|
||||||
|
string(8) "my value"
|
||||||
|
string(12) "newattribute"
|
||||||
|
string(12) "my new value"
|
||||||
|
<?xml version="1.0"?>
|
||||||
|
<container newattribute="my new value"/>
|
||||||
|
<?xml version="1.0"?>
|
||||||
|
<container newattribute="my new value" newnewattribute="my even newer value"/>
|
32
ext/dom/tests/manually_call_constructor/cdatasection.phpt
Normal file
32
ext/dom/tests/manually_call_constructor/cdatasection.phpt
Normal file
|
@ -0,0 +1,32 @@
|
||||||
|
--TEST--
|
||||||
|
Manually call __construct() - CDATA section variation
|
||||||
|
--EXTENSIONS--
|
||||||
|
dom
|
||||||
|
--FILE--
|
||||||
|
<?php
|
||||||
|
|
||||||
|
$cdata = new DOMCdataSection("my value");
|
||||||
|
var_dump($cdata->nodeValue);
|
||||||
|
$cdata->__construct("my new value");
|
||||||
|
var_dump($cdata->nodeValue);
|
||||||
|
|
||||||
|
$doc = new DOMDocument();
|
||||||
|
$doc->loadXML(<<<XML
|
||||||
|
<?xml version="1.0"?>
|
||||||
|
<container/>
|
||||||
|
XML);
|
||||||
|
$doc->documentElement->appendChild($cdata);
|
||||||
|
echo $doc->saveXML();
|
||||||
|
|
||||||
|
$cdata->__construct("my even newer value");
|
||||||
|
$doc->documentElement->appendChild($cdata);
|
||||||
|
echo $doc->saveXML();
|
||||||
|
|
||||||
|
?>
|
||||||
|
--EXPECT--
|
||||||
|
string(8) "my value"
|
||||||
|
string(12) "my new value"
|
||||||
|
<?xml version="1.0"?>
|
||||||
|
<container><![CDATA[my new value]]></container>
|
||||||
|
<?xml version="1.0"?>
|
||||||
|
<container><![CDATA[my new value]]><![CDATA[my even newer value]]></container>
|
34
ext/dom/tests/manually_call_constructor/comment.phpt
Normal file
34
ext/dom/tests/manually_call_constructor/comment.phpt
Normal file
|
@ -0,0 +1,34 @@
|
||||||
|
--TEST--
|
||||||
|
Manually call __construct() - comment variation
|
||||||
|
--EXTENSIONS--
|
||||||
|
dom
|
||||||
|
--FILE--
|
||||||
|
<?php
|
||||||
|
|
||||||
|
$comment = new DOMComment("my value");
|
||||||
|
var_dump($comment->nodeName, $comment->nodeValue);
|
||||||
|
$comment->__construct("my new value");
|
||||||
|
var_dump($comment->nodeName, $comment->nodeValue);
|
||||||
|
|
||||||
|
$doc = new DOMDocument();
|
||||||
|
$doc->loadXML(<<<XML
|
||||||
|
<?xml version="1.0"?>
|
||||||
|
<container/>
|
||||||
|
XML);
|
||||||
|
$doc->documentElement->appendChild($comment);
|
||||||
|
echo $doc->saveXML();
|
||||||
|
|
||||||
|
$comment->__construct("my even newer value");
|
||||||
|
$doc->documentElement->appendChild($comment);
|
||||||
|
echo $doc->saveXML();
|
||||||
|
|
||||||
|
?>
|
||||||
|
--EXPECT--
|
||||||
|
string(8) "#comment"
|
||||||
|
string(8) "my value"
|
||||||
|
string(8) "#comment"
|
||||||
|
string(12) "my new value"
|
||||||
|
<?xml version="1.0"?>
|
||||||
|
<container><!--my new value--></container>
|
||||||
|
<?xml version="1.0"?>
|
||||||
|
<container><!--my new value--><!--my even newer value--></container>
|
15
ext/dom/tests/manually_call_constructor/document.phpt
Normal file
15
ext/dom/tests/manually_call_constructor/document.phpt
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
--TEST--
|
||||||
|
Manually call __construct() - document variation
|
||||||
|
--EXTENSIONS--
|
||||||
|
dom
|
||||||
|
--FILE--
|
||||||
|
<?php
|
||||||
|
|
||||||
|
$doc = new DOMDocument();
|
||||||
|
$doc->loadXML('<?xml version="1.0"?><foo/>');
|
||||||
|
$doc->__construct("1.1", "UTF-8");
|
||||||
|
echo $doc->saveXML();
|
||||||
|
|
||||||
|
?>
|
||||||
|
--EXPECT--
|
||||||
|
<?xml version="1.1" encoding="UTF-8"?>
|
|
@ -0,0 +1,32 @@
|
||||||
|
--TEST--
|
||||||
|
Manually call __construct() - document fragment variation
|
||||||
|
--EXTENSIONS--
|
||||||
|
dom
|
||||||
|
--FILE--
|
||||||
|
<?php
|
||||||
|
|
||||||
|
$fragment = new DOMDocumentFragment();
|
||||||
|
var_dump($fragment->textContent);
|
||||||
|
$fragment->__construct();
|
||||||
|
var_dump($fragment->textContent);
|
||||||
|
|
||||||
|
$doc = new DOMDocument();
|
||||||
|
$doc->loadXML(<<<XML
|
||||||
|
<?xml version="1.0"?>
|
||||||
|
<container/>
|
||||||
|
XML);
|
||||||
|
@$doc->documentElement->appendChild($fragment);
|
||||||
|
echo $doc->saveXML();
|
||||||
|
|
||||||
|
$fragment->__construct();
|
||||||
|
@$doc->documentElement->appendChild($fragment);
|
||||||
|
echo $doc->saveXML();
|
||||||
|
|
||||||
|
?>
|
||||||
|
--EXPECT--
|
||||||
|
string(0) ""
|
||||||
|
string(0) ""
|
||||||
|
<?xml version="1.0"?>
|
||||||
|
<container/>
|
||||||
|
<?xml version="1.0"?>
|
||||||
|
<container/>
|
34
ext/dom/tests/manually_call_constructor/element.phpt
Normal file
34
ext/dom/tests/manually_call_constructor/element.phpt
Normal file
|
@ -0,0 +1,34 @@
|
||||||
|
--TEST--
|
||||||
|
Manually call __construct() - element variation
|
||||||
|
--EXTENSIONS--
|
||||||
|
dom
|
||||||
|
--FILE--
|
||||||
|
<?php
|
||||||
|
|
||||||
|
$element = new DOMElement('foo', 'my value');
|
||||||
|
var_dump($element->nodeName, $element->textContent);
|
||||||
|
$element->__construct('foo2', 'my new value');
|
||||||
|
var_dump($element->nodeName, $element->textContent);
|
||||||
|
|
||||||
|
$doc = new DOMDocument();
|
||||||
|
$doc->loadXML(<<<XML
|
||||||
|
<?xml version="1.0"?>
|
||||||
|
<container/>
|
||||||
|
XML);
|
||||||
|
$doc->documentElement->appendChild($element);
|
||||||
|
echo $doc->saveXML();
|
||||||
|
|
||||||
|
$element->__construct('foo3', 'my new new value');
|
||||||
|
$doc->documentElement->appendChild($element);
|
||||||
|
echo $doc->saveXML();
|
||||||
|
|
||||||
|
?>
|
||||||
|
--EXPECT--
|
||||||
|
string(3) "foo"
|
||||||
|
string(8) "my value"
|
||||||
|
string(4) "foo2"
|
||||||
|
string(12) "my new value"
|
||||||
|
<?xml version="1.0"?>
|
||||||
|
<container><foo2>my new value</foo2></container>
|
||||||
|
<?xml version="1.0"?>
|
||||||
|
<container><foo2>my new value</foo2><foo3>my new new value</foo3></container>
|
34
ext/dom/tests/manually_call_constructor/entityreference.phpt
Normal file
34
ext/dom/tests/manually_call_constructor/entityreference.phpt
Normal file
|
@ -0,0 +1,34 @@
|
||||||
|
--TEST--
|
||||||
|
Manually call __construct() - entity reference variation
|
||||||
|
--EXTENSIONS--
|
||||||
|
dom
|
||||||
|
--FILE--
|
||||||
|
<?php
|
||||||
|
|
||||||
|
$entityRef = new DOMEntityReference('foo');
|
||||||
|
var_dump($entityRef->nodeName, $entityRef->textContent);
|
||||||
|
$entityRef->__construct('foo2');
|
||||||
|
var_dump($entityRef->nodeName, $entityRef->textContent);
|
||||||
|
|
||||||
|
$doc = new DOMDocument();
|
||||||
|
$doc->loadXML(<<<XML
|
||||||
|
<?xml version="1.0"?>
|
||||||
|
<container/>
|
||||||
|
XML);
|
||||||
|
$doc->documentElement->appendChild($entityRef);
|
||||||
|
echo $doc->saveXML();
|
||||||
|
|
||||||
|
$entityRef->__construct('foo3');
|
||||||
|
$doc->documentElement->appendChild($entityRef);
|
||||||
|
echo $doc->saveXML();
|
||||||
|
|
||||||
|
?>
|
||||||
|
--EXPECT--
|
||||||
|
string(3) "foo"
|
||||||
|
string(0) ""
|
||||||
|
string(4) "foo2"
|
||||||
|
string(0) ""
|
||||||
|
<?xml version="1.0"?>
|
||||||
|
<container>&foo2;</container>
|
||||||
|
<?xml version="1.0"?>
|
||||||
|
<container>&foo2;&foo3;</container>
|
|
@ -0,0 +1,34 @@
|
||||||
|
--TEST--
|
||||||
|
Manually call __construct() - processing instruction variation
|
||||||
|
--EXTENSIONS--
|
||||||
|
dom
|
||||||
|
--FILE--
|
||||||
|
<?php
|
||||||
|
|
||||||
|
$pi = new DOMProcessingInstruction('name1', 'value1');
|
||||||
|
var_dump($pi->target, $pi->data);
|
||||||
|
$pi->__construct('name2', 'value2');
|
||||||
|
var_dump($pi->target, $pi->data);
|
||||||
|
|
||||||
|
$doc = new DOMDocument();
|
||||||
|
$doc->loadXML(<<<XML
|
||||||
|
<?xml version="1.0"?>
|
||||||
|
<container/>
|
||||||
|
XML);
|
||||||
|
$doc->documentElement->appendChild($pi);
|
||||||
|
echo $doc->saveXML();
|
||||||
|
|
||||||
|
$pi->__construct('name3', 'value3');
|
||||||
|
$doc->documentElement->appendChild($pi);
|
||||||
|
echo $doc->saveXML();
|
||||||
|
|
||||||
|
?>
|
||||||
|
--EXPECT--
|
||||||
|
string(5) "name1"
|
||||||
|
string(6) "value1"
|
||||||
|
string(5) "name2"
|
||||||
|
string(6) "value2"
|
||||||
|
<?xml version="1.0"?>
|
||||||
|
<container><?name2 value2?></container>
|
||||||
|
<?xml version="1.0"?>
|
||||||
|
<container><?name2 value2?><?name3 value3?></container>
|
33
ext/dom/tests/manually_call_constructor/text.phpt
Normal file
33
ext/dom/tests/manually_call_constructor/text.phpt
Normal file
|
@ -0,0 +1,33 @@
|
||||||
|
--TEST--
|
||||||
|
Manually call __construct() - text variation
|
||||||
|
--EXTENSIONS--
|
||||||
|
dom
|
||||||
|
--FILE--
|
||||||
|
<?php
|
||||||
|
|
||||||
|
$text = new DOMText('my value');
|
||||||
|
var_dump($text->textContent);
|
||||||
|
$text->__construct('my new value');
|
||||||
|
var_dump($text->textContent);
|
||||||
|
|
||||||
|
$doc = new DOMDocument();
|
||||||
|
$doc->loadXML(<<<XML
|
||||||
|
<?xml version="1.0"?>
|
||||||
|
<container/>
|
||||||
|
XML);
|
||||||
|
$doc->documentElement->appendChild($text);
|
||||||
|
echo $doc->saveXML();
|
||||||
|
|
||||||
|
$text->__construct("\nmy new new value");
|
||||||
|
$doc->documentElement->appendChild($text);
|
||||||
|
echo $doc->saveXML();
|
||||||
|
|
||||||
|
?>
|
||||||
|
--EXPECT--
|
||||||
|
string(8) "my value"
|
||||||
|
string(12) "my new value"
|
||||||
|
<?xml version="1.0"?>
|
||||||
|
<container>my new value</container>
|
||||||
|
<?xml version="1.0"?>
|
||||||
|
<container>my new value
|
||||||
|
my new new value</container>
|
|
@ -51,13 +51,11 @@ PHP_METHOD(DOMText, __construct)
|
||||||
}
|
}
|
||||||
|
|
||||||
intern = Z_DOMOBJ_P(ZEND_THIS);
|
intern = Z_DOMOBJ_P(ZEND_THIS);
|
||||||
if (intern != NULL) {
|
oldnode = dom_object_get_node(intern);
|
||||||
oldnode = dom_object_get_node(intern);
|
if (oldnode != NULL) {
|
||||||
if (oldnode != NULL) {
|
php_libxml_node_decrement_resource((php_libxml_node_object *)intern);
|
||||||
php_libxml_node_free_resource(oldnode );
|
|
||||||
}
|
|
||||||
php_libxml_increment_node_ptr((php_libxml_node_object *)intern, nodep, (void *)intern);
|
|
||||||
}
|
}
|
||||||
|
php_libxml_increment_node_ptr((php_libxml_node_object *)intern, nodep, (void *)intern);
|
||||||
}
|
}
|
||||||
/* }}} end DOMText::__construct */
|
/* }}} end DOMText::__construct */
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue