Skip to content
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

Merged
merged 9 commits into from
Sep 20, 2017
Merged

Added SimpleXMLElement Exception check #222

merged 9 commits into from
Sep 20, 2017

Conversation

yasar-luo
Copy link
Contributor

@yasar-luo yasar-luo commented Sep 18, 2017

This is:

  • a bugfix
  • a new feature

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.

@PowerKiKi PowerKiKi added missing test reader/xml Reader for MS SpreadsheetML spreadsheet files labels Sep 18, 2017
@@ -167,6 +170,9 @@ public function listWorksheetInfo($pFilename)
'SimpleXMLElement',
Settings::getLibXmlLoaderOptions()
);
if (!($xml instanceof \SimpleXMLElement)) {
Copy link
Member

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.

@@ -138,6 +138,9 @@ public function listWorksheetNames($pFilename)
'SimpleXMLElement',
Settings::getLibXmlLoaderOptions()
);
if (!($xml instanceof \SimpleXMLElement)) {
throw new Exception('SimpleXMLElement can not load ' . $pFilename);
Copy link
Member

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.

Copy link
Contributor Author

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.

@@ -344,6 +350,9 @@ public function loadIntoExisting($pFilename, Spreadsheet $spreadsheet)
'SimpleXMLElement',
Settings::getLibXmlLoaderOptions()
);
if (!($xml instanceof \SimpleXMLElement)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

idem

@yasar-luo
Copy link
Contributor Author

@PowerKiKi I had added the unit test and change log and fixed the code style.

@PowerKiKi PowerKiKi merged commit 0477e6f into PHPOffice:develop Sep 20, 2017
@PowerKiKi
Copy link
Member

Thanks !

@yasar-luo
Copy link
Contributor Author

@PowerKiKi my pleasure

@yasar-luo yasar-luo deleted the develop918_1 branch September 20, 2017 05:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
missing test reader/xml Reader for MS SpreadsheetML spreadsheet files
Development

Successfully merging this pull request may close these issues.

2 participants