[php-src] Issue #11830: ParentNode methods should perform their checks upfront
| From: | nielsdos | Date: | Sun, 30 Jul 2023 18:28:34 +0000 |
| Subject: | [php-src] Issue #11830: ParentNode methods should perform their checks upfront | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-245068@lists.php.net to get a copy of this message | ||
Issue: https://github.com/php/php-src/issues/11830
Author: nielsdos
### Description
The following code:
```php
<?php
$doc = new DOMDocument;
$doc->loadXML(<<<XML
<?xml version="1.0"?>
<container x="foo">
<test/>
</container>
XML);
try {
$doc->documentElement->firstElementChild->append($doc->documentElement->attributes[0]);
} catch (\DOMException $e) {
echo $e->getMessage(), "\n";
}
echo $doc->saveXML();
```
Resulted in this output:
```
Hierarchy Request Error
<?xml version="1.0"?>
<container>
<test/>
</container>
```
But I expected this output instead:
```
Hierarchy Request Error
<?xml version="1.0"?>
<container x="foo">
<test/>
</container>
```
This is because the hierarchy checks are done upon the creation of the fragment, instead of upfront.
We should move all the hierarchy and type checking logic upfront.
It looks like this has been around since the introduction of these ParentNode methods.
### PHP Version
8.0+
### Operating System
_No response_