Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix GH-12192: SimpleXML infinite loop when getName() is called within…
… foreach This happens because getName() resets the iterator to the start because it overwrites the iterator data. We add a version of get_first_node that does not overwrite the iterator data. Closes GH-12193.
- Loading branch information
Showing
3 changed files
with
65 additions
and
8 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,37 @@ | ||
--TEST-- | ||
GH-12192 (SimpleXML infinite loop when getName() is called within foreach) | ||
--EXTENSIONS-- | ||
simplexml | ||
--FILE-- | ||
<?php | ||
|
||
$xml = "<root><a>1</a><a>2</a></root>"; | ||
$xml = simplexml_load_string($xml); | ||
|
||
$a = $xml->a; | ||
|
||
foreach ($a as $test) { | ||
echo "Iteration\n"; | ||
var_dump($a->key()); | ||
var_dump($a->getName()); | ||
var_dump((string) $test); | ||
} | ||
|
||
var_dump($a); | ||
|
||
?> | ||
--EXPECT-- | ||
Iteration | ||
string(1) "a" | ||
string(1) "a" | ||
string(1) "1" | ||
Iteration | ||
string(1) "a" | ||
string(1) "a" | ||
string(1) "2" | ||
object(SimpleXMLElement)#2 (2) { | ||
[0]=> | ||
string(1) "1" | ||
[1]=> | ||
string(1) "2" | ||
} |