Skip to content

Added SimpleXMLElement Exception check#222

Merged
PowerKiKi merged 9 commits intoPHPOffice:developfrom
yasar-luo:develop918_1
Sep 20, 2017
Merged

Added SimpleXMLElement Exception check#222
PowerKiKi merged 9 commits intoPHPOffice:developfrom
yasar-luo:develop918_1

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
'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.

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.

'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
BlackyTay pushed a commit to BlackyTay/PhpSpreadsheet that referenced this pull request Aug 8, 2025
When the xml file 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 showing the error, we throw an exception.
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