Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix GH-11830: ParentNode methods should perform their checks upfront
Closes GH-11887.
- Loading branch information
Showing
6 changed files
with
330 additions
and
70 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
--TEST-- | ||
GH-11830 (ParentNode methods should perform their checks upfront) - attribute variation | ||
--EXTENSIONS-- | ||
dom | ||
--FILE-- | ||
<?php | ||
$doc = new DOMDocument; | ||
$doc->loadXML(<<<XML | ||
<?xml version="1.0"?> | ||
<container x="foo"> | ||
<test/> | ||
</container> | ||
XML); | ||
|
||
try { | ||
$doc->documentElement->firstElementChild->prepend($doc->documentElement->attributes[0]); | ||
} catch (\DOMException $e) { | ||
echo $e->getMessage(), "\n"; | ||
} | ||
|
||
try { | ||
$doc->documentElement->firstElementChild->append($doc->documentElement->attributes[0]); | ||
} catch (\DOMException $e) { | ||
echo $e->getMessage(), "\n"; | ||
} | ||
|
||
try { | ||
$doc->documentElement->firstElementChild->before($doc->documentElement->attributes[0]); | ||
} catch (\DOMException $e) { | ||
echo $e->getMessage(), "\n"; | ||
} | ||
|
||
try { | ||
$doc->documentElement->firstElementChild->after($doc->documentElement->attributes[0]); | ||
} catch (\DOMException $e) { | ||
echo $e->getMessage(), "\n"; | ||
} | ||
|
||
try { | ||
$doc->documentElement->firstElementChild->replaceWith($doc->documentElement->attributes[0]); | ||
} catch (\DOMException $e) { | ||
echo $e->getMessage(), "\n"; | ||
} | ||
|
||
echo $doc->saveXML(); | ||
?> | ||
--EXPECT-- | ||
Hierarchy Request Error | ||
Hierarchy Request Error | ||
Hierarchy Request Error | ||
Hierarchy Request Error | ||
Hierarchy Request Error | ||
<?xml version="1.0"?> | ||
<container x="foo"> | ||
<test/> | ||
</container> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
--TEST-- | ||
GH-11830 (ParentNode methods should perform their checks upfront) - document variation | ||
--EXTENSIONS-- | ||
dom | ||
--FILE-- | ||
<?php | ||
$otherDoc = new DOMDocument; | ||
$otherDoc->loadXML(<<<XML | ||
<?xml version="1.0"?> | ||
<other/> | ||
XML); | ||
|
||
$otherElement = $otherDoc->documentElement; | ||
|
||
$doc = new DOMDocument; | ||
$doc->loadXML(<<<XML | ||
<?xml version="1.0"?> | ||
<container> | ||
<alone/> | ||
<child><testelement/></child> | ||
</container> | ||
XML); | ||
|
||
$testElement = $doc->documentElement->firstElementChild->nextElementSibling->firstElementChild; | ||
|
||
try { | ||
$doc->documentElement->firstElementChild->prepend($testElement, $otherElement); | ||
} catch (\DOMException $e) { | ||
echo $e->getMessage(), "\n"; | ||
} | ||
|
||
try { | ||
$doc->documentElement->firstElementChild->append($testElement, $otherElement); | ||
} catch (\DOMException $e) { | ||
echo $e->getMessage(), "\n"; | ||
} | ||
|
||
try { | ||
$doc->documentElement->firstElementChild->before($testElement, $otherElement); | ||
} catch (\DOMException $e) { | ||
echo $e->getMessage(), "\n"; | ||
} | ||
|
||
try { | ||
$doc->documentElement->firstElementChild->after($testElement, $otherElement); | ||
} catch (\DOMException $e) { | ||
echo $e->getMessage(), "\n"; | ||
} | ||
|
||
try { | ||
$doc->documentElement->firstElementChild->replaceWith($testElement, $otherElement); | ||
} catch (\DOMException $e) { | ||
echo $e->getMessage(), "\n"; | ||
} | ||
|
||
echo $otherDoc->saveXML(); | ||
echo $doc->saveXML(); | ||
?> | ||
--EXPECT-- | ||
Wrong Document Error | ||
Wrong Document Error | ||
Wrong Document Error | ||
Wrong Document Error | ||
Wrong Document Error | ||
<?xml version="1.0"?> | ||
<other/> | ||
<?xml version="1.0"?> | ||
<container> | ||
<alone/> | ||
<child><testelement/></child> | ||
</container> |
Oops, something went wrong.