Skip to content

ParentNode methods should perform their checks upfront #11830

Closed

Description

@ndossche

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

Activity

  1. added a commit that references this issue on Aug 5, 2023
    e5c3d6b
  2. added 2 commits that reference this issue on Aug 7, 2023
    dddd309
    b80ded8
  3. added a commit that references this issue on Aug 7, 2023
    3ad5029
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions