-
-
Save goozak/aa3f5bd5a146a51ddd75 to your computer and use it in GitHub Desktop.
XMLReader bug
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
<?php | |
//Bug in PHP 5.5 and PHP 5.6 with XMLReader and specialy crafted XML | |
TestXML('https://www.dropbox.com/s/6uzaf0mqlp8znk9/XMLReaderGood.xml?dl=1'); | |
echo '<hr>'; | |
//This will report "Input is not proper UTF-8, indicate encoding !", which is incorrect | |
TestXML('https://www.dropbox.com/s/nkphfqbotxaogw7/XMLReaderBad.xml?dl=1'); | |
function TestXML($file) { | |
$XR = new XMLReader; | |
$XR->open($file, null, LIBXML_NOBLANKS); | |
while (($lastRead = $XR->read()) && ($XR->name !== 'records')) { ; } | |
while (($lastRead = $XR->read()) && ($XR->name !== 'record')) { ; } | |
while ($lastRead) { | |
$xml = $XR->readOuterXML(); | |
if ($xml === '') { | |
$err = ''; | |
if ($e = libxml_get_last_error()) { $err = $e->message.' (line: '.$e->line.')'; } | |
$XR->close(); | |
echo $file.' : Problem with file'.($err ? ' — '.$err : '').'.'; | |
return; | |
} | |
while (($lastRead = $XR->next()) && ($XR->name !== 'record')) { ; } | |
} | |
$XR->close(); | |
echo $file.' : Good!'; | |
return; | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment