1
0
mirror of https://github.com/php/php-src.git synced 2026-03-24 08:12:21 +01:00
Files
archived-php-src/ext/dom/tests/delayed_freeing/entity_reference.phpt
Niels Dossche 003ebdd039 Fix GH-9628: Implicitly removing nodes from \DOMDocument breaks existing references
Change the way lifetime works in ext/libxml and ext/dom

Previously, a node could be freed even when holding a userland reference
to it. This resulted in exceptions when trying to access that node after
it has been implicitly or explicitly removed. After this patch, a node
will only be freed when the last userland reference disappears.

Fixes GH-9628.
Closes GH-11576.
2023-07-03 21:31:57 +02:00

49 lines
1.1 KiB
PHP

--TEST--
Delayed freeing entity reference
--EXTENSIONS--
dom
--FILE--
<?php
$doc = new DOMDocument;
$entityRef = $doc->appendChild($doc->createElementNS('some:ns', 'container'))
->appendChild($doc->createEntityReference('nbsp'));
echo $doc->saveXML(), "\n";
$entityRef->parentNode->remove();
echo $doc->saveXML(), "\n";
var_dump($entityRef->parentNode);
var_dump($entityRef->nodeName);
var_dump($entityRef->textContent);
$doc = new DOMDocument;
$doc->loadXML(<<<'XML'
<?xml version="1.0"?>
<!DOCTYPE books [
<!ENTITY test "entity is only for test purposes">
]>
<div/>
XML);
$entityRef = $doc->documentElement->appendChild($doc->createEntityReference('test'));
echo $doc->saveXML(), "\n";
$entityRef->parentNode->remove();
unset($doc);
var_dump($entityRef->nodeName);
var_dump($entityRef->textContent);
?>
--EXPECT--
<?xml version="1.0"?>
<container xmlns="some:ns">&nbsp;</container>
<?xml version="1.0"?>
NULL
string(4) "nbsp"
string(0) ""
<?xml version="1.0"?>
<!DOCTYPE books [
<!ENTITY test "entity is only for test purposes">
]>
<div>&test;</div>
string(4) "test"
string(0) ""