Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ParentNode methods should perform their checks upfront #11830

Closed
nielsdos opened this issue Jul 30, 2023 · 0 comments
Closed

ParentNode methods should perform their checks upfront #11830

nielsdos opened this issue Jul 30, 2023 · 0 comments

Comments

@nielsdos
Copy link
Member

Description

The following code:

<?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

nielsdos added a commit that referenced this issue Aug 7, 2023
* PHP-8.1:
  Fix GH-11830: ParentNode methods should perform their checks upfront
  Fix manually calling __construct() on DOM classes
nielsdos added a commit that referenced this issue Aug 7, 2023
* PHP-8.2:
  Fix GH-11830: ParentNode methods should perform their checks upfront
  Fix manually calling __construct() on DOM classes
jorgsowa pushed a commit to jorgsowa/php-src that referenced this issue Aug 16, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant