From ad5ee8a2b7ad960ba8286d11ff98d53098f72c97 Mon Sep 17 00:00:00 2001 From: nielsdos <7771979+nielsdos@users.noreply.github.com> Date: Mon, 19 Jun 2023 19:52:28 +0200 Subject: [PATCH] Revert changes to DOMAttr::$value and DOMAttr::$nodeValue expansion Closes GH-11469. --- NEWS | 2 + UPGRADING | 4 -- ext/dom/attr.c | 3 +- ext/dom/node.c | 3 -- ext/dom/tests/DOMAttr_entity_expansion.phpt | 54 --------------------- 5 files changed, 3 insertions(+), 63 deletions(-) delete mode 100644 ext/dom/tests/DOMAttr_entity_expansion.phpt diff --git a/NEWS b/NEWS index 336eb3b433118..4e2980908b179 100644 --- a/NEWS +++ b/NEWS @@ -13,6 +13,8 @@ PHP NEWS (nielsdos) . Fix #77894 (DOMNode::C14N() very slow on generated DOMDocuments even after normalisation). (nielsdos) + . Revert changes to DOMAttr::$value and DOMAttr::$nodeValue expansion. + (nielsdos) - GD: . Removed imagerotate "ignore_transparent" argument since it has no effect. diff --git a/UPGRADING b/UPGRADING index a9de43fc0ca0e..5d06a74ce4b3f 100644 --- a/UPGRADING +++ b/UPGRADING @@ -44,10 +44,6 @@ PHP 8.3 UPGRADE NOTES . Static variable initializers can now contain arbitrary expressions. RFC: https://wiki.php.net/rfc/arbitrary_static_variable_initializers -- DOM: - . Assignment to DOMAttr::$value and DOMAttr::$nodeValue no longer expands - entities in the new value. - - FFI: . C functions that have a return type of void now return null instead of returning the following object object(FFI\CData:void) { } diff --git a/ext/dom/attr.c b/ext/dom/attr.c index 417f92a25c364..0a558a7664284 100644 --- a/ext/dom/attr.c +++ b/ext/dom/attr.c @@ -148,8 +148,7 @@ int dom_attr_value_write(dom_object *obj, zval *newval) } dom_remove_all_children((xmlNodePtr) attrp); - xmlNodePtr node = xmlNewTextLen((xmlChar *) ZSTR_VAL(str), ZSTR_LEN(str)); - xmlAddChild((xmlNodePtr) attrp, node); + xmlNodeSetContentLen((xmlNodePtr) attrp, (xmlChar *) ZSTR_VAL(str), ZSTR_LEN(str)); zend_string_release_ex(str, 0); return SUCCESS; diff --git a/ext/dom/node.c b/ext/dom/node.c index 29262f8579146..7fb45efc3af35 100644 --- a/ext/dom/node.c +++ b/ext/dom/node.c @@ -178,9 +178,6 @@ int dom_node_node_value_write(dom_object *obj, zval *newval) /* Access to Element node is implemented as a convenience method */ switch (nodep->type) { case XML_ATTRIBUTE_NODE: - dom_remove_all_children(nodep); - xmlAddChild(nodep, xmlNewTextLen((xmlChar *) ZSTR_VAL(str), ZSTR_LEN(str))); - break; case XML_ELEMENT_NODE: dom_remove_all_children(nodep); ZEND_FALLTHROUGH; diff --git a/ext/dom/tests/DOMAttr_entity_expansion.phpt b/ext/dom/tests/DOMAttr_entity_expansion.phpt deleted file mode 100644 index e3482d1a9d739..0000000000000 --- a/ext/dom/tests/DOMAttr_entity_expansion.phpt +++ /dev/null @@ -1,54 +0,0 @@ ---TEST-- -DOMAttr entity expansion ---EXTENSIONS-- -dom ---FILE-- -createElement('elt'); -$doc->appendChild($elt); -$elt->setAttribute('a','&'); -print $doc->saveXML($elt) . "\n"; - -$attr = $elt->getAttributeNode('a'); -$attr->value = '&'; -print "$attr->value\n"; -print $doc->saveXML($elt) . "\n"; - -$attr->removeChild($attr->firstChild); -print $doc->saveXML($elt) . "\n"; - -$attr->nodeValue = '&'; -print "$attr->nodeValue\n"; -print $doc->saveXML($elt) . "\n"; - -$attr->nodeValue = '&'; -print "$attr->nodeValue\n"; -print $doc->saveXML($elt) . "\n"; - -$elt->removeAttributeNode($attr); -$elt->setAttributeNS('http://www.w3.org/2000/svg', 'svg:id','&'); -print $doc->saveXML($elt) . "\n"; - -$attr = $elt->getAttributeNodeNS('http://www.w3.org/2000/svg', 'id'); -$attr->value = '<&'; -print "$attr->value\n"; -print $doc->saveXML($elt) . "\n"; - -$node = new DOMAttr('foo','bar'); -$node->nodeValue = 'xx1yy'; -print "$node->nodeValue\n"; -?> ---EXPECT-- - -& - - -& - -& - - -<& - -xx1yy