-
Notifications
You must be signed in to change notification settings - Fork 3.5k
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
Added SimpleXMLElement Exception check #222
Conversation
src/PhpSpreadsheet/Reader/Xml.php
Outdated
@@ -167,6 +170,9 @@ public function listWorksheetInfo($pFilename) | |||
'SimpleXMLElement', | |||
Settings::getLibXmlLoaderOptions() | |||
); | |||
if (!($xml instanceof \SimpleXMLElement)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should compare against false
instead of checking types, so if ($xml === false)
.
Error message should include error details from simplexml.
src/PhpSpreadsheet/Reader/Xml.php
Outdated
@@ -138,6 +138,9 @@ public function listWorksheetNames($pFilename) | |||
'SimpleXMLElement', | |||
Settings::getLibXmlLoaderOptions() | |||
); | |||
if (!($xml instanceof \SimpleXMLElement)) { | |||
throw new Exception('SimpleXMLElement can not load ' . $pFilename); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should compare against false
instead of checking types, so if ($xml === false)
.
Error message should include error details from simplexml.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
function simplexml_load_string returns:
SimpleXMLElement an object of class SimpleXMLElement with * properties containing the data held within the xml document, or FALSE on failure.
It just return false when error occurred, so there's no more error information.
src/PhpSpreadsheet/Reader/Xml.php
Outdated
@@ -344,6 +350,9 @@ public function loadIntoExisting($pFilename, Spreadsheet $spreadsheet) | |||
'SimpleXMLElement', | |||
Settings::getLibXmlLoaderOptions() | |||
); | |||
if (!($xml instanceof \SimpleXMLElement)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
idem
@PowerKiKi I had added the unit test and change log and fixed the code style. |
Thanks ! |
@PowerKiKi my pleasure |
This is:
Checklist:
What does it change?
When the xml file get is not a standard xml file, the simplexml_load_string will return false, this will cause an error on "$xml->getNamespaces(true);" . So, instead of show the error, throw an exception may be better for it.