mirror of
https://github.com/php/php-src.git
synced 2025-08-16 05:58:45 +02:00
Merge branch 'PHP-8.3' into PHP-8.4
* PHP-8.3: Fix xinclude destruction of live attributes
This commit is contained in:
commit
2c45d67ad3
3 changed files with 33 additions and 7 deletions
|
@ -1669,14 +1669,28 @@ PHP_METHOD(Dom_XMLDocument, saveXml)
|
|||
}
|
||||
/* }}} end dom_document_savexml */
|
||||
|
||||
static void dom_xinclude_strip_references_for_attributes(xmlNodePtr basep)
|
||||
{
|
||||
for (xmlAttrPtr prop = basep->properties; prop; prop = prop->next) {
|
||||
php_libxml_node_free_resource((xmlNodePtr) prop);
|
||||
for (xmlNodePtr child = prop->children; child; child = child->next) {
|
||||
php_libxml_node_free_resource(child);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void dom_xinclude_strip_references(xmlNodePtr basep)
|
||||
{
|
||||
php_libxml_node_free_resource(basep);
|
||||
dom_xinclude_strip_references_for_attributes(basep);
|
||||
|
||||
xmlNodePtr current = basep->children;
|
||||
|
||||
while (current) {
|
||||
php_libxml_node_free_resource(current);
|
||||
if (current->type == XML_ELEMENT_NODE) {
|
||||
dom_xinclude_strip_references_for_attributes(current);
|
||||
}
|
||||
current = php_dom_next_in_tree_order(current, basep);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -13,7 +13,7 @@ $doc->loadXML(<<<XML
|
|||
</xi:include>
|
||||
<xi:test xmlns:xi="http://www.w3.org/2001/XInclude">
|
||||
<xi:include href="thisisnonexistent">
|
||||
<p>garbage</p>
|
||||
<p attr="foo" attr2="bar">garbage</p>
|
||||
</xi:include>
|
||||
</xi:test>
|
||||
</root>
|
||||
|
@ -22,20 +22,31 @@ XML);
|
|||
$xpath = new DOMXPath($doc);
|
||||
|
||||
$garbage = [];
|
||||
foreach ($xpath->query('//p') as $entry)
|
||||
foreach ($xpath->query('//p') as $entry) {
|
||||
$garbage[] = $entry;
|
||||
foreach ($entry->attributes as $attr) {
|
||||
$garbage[] = $attr;
|
||||
foreach ($attr->childNodes as $child) {
|
||||
$garbage[] = $child;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@$doc->xinclude();
|
||||
|
||||
foreach ($garbage as $node) {
|
||||
try {
|
||||
var_dump($node->localName);
|
||||
} catch (DOMException $e) {
|
||||
echo $e->getMessage(), "\n";
|
||||
}
|
||||
try {
|
||||
var_dump($node->localName);
|
||||
} catch (DOMException $e) {
|
||||
echo $e->getMessage(), "\n";
|
||||
}
|
||||
}
|
||||
?>
|
||||
--EXPECT--
|
||||
Invalid State Error
|
||||
Invalid State Error
|
||||
Invalid State Error
|
||||
Invalid State Error
|
||||
Invalid State Error
|
||||
Invalid State Error
|
||||
Invalid State Error
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue