-
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
Fixes #801 libxml_disable_entity_loader() is changed #802
Conversation
This would be one way to fix #787 Somehow when I try to load a PDF the `XmlScanner::getInstance()` is called many times: A new `getInstance()` is called before the `__destruct()` of the previous one, causing the `previousLibxmlDisableEntityLoaderValue` to contain `false` even when the original value was `true`. My solution was to share `$previousLibxmlDisableEntityLoaderValue` accross all instances, and be sure to not overwrite the original value.
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.
Looks good to me, but before merging, unit tests should be added to cover the cases you describe.
We also faced issues new XmlScanner behavior and I'm afraid that proposed solution will not work in our case. Code below will print "failed to load external entity "/data/test.xml"" for any valid test.xml file $reader = new \PhpOffice\PhpSpreadsheet\Reader\Xlsx();
libxml_use_internal_errors(true);
libxml_clear_errors();
$document = new DOMDocument();
$document->load("test.xml");
echo libxml_get_last_error()->message. "\n"; Because libxml_disable_entity_loader(true) disables loading from file. Both issues can be fixed by moving all enabling/disabling logic out of constructor/desctructor to public function scan($xml)
{
if ($this->libxmlDisableEntityLoader) {
$this->previousLibxmlDisableEntityLoaderValue = libxml_disable_entity_loader(true);
}
// all old code here
if ($this->libxmlDisableEntityLoader) {
libxml_disable_entity_loader($this->previousLibxmlDisableEntityLoaderValue);
}
return $xml;
} What do you think? |
Yes, moving the logic to scan() seams looks good to me (works for my case
too), changing global parameters for the shorter time possible is always a
good idea.
Just be sure to never call a scan() within a scan() !
|
Should I submit a new PR, or you will update this one?
|
I think the point of using the constructor/destructor is to be certain that it will be done. So if we move the logic to the scan method, it should use a @philipp-kolesnikov feel free to open a new PR, but be sure to include unit tests, in order to be merged faster. Also on a sidenote, |
…sed as local as possible Fixes PHPOffice#801 Closes PHPOffice#802 Closes PHPOffice#803
This would be one way to fix #801
Somehow when I try to load a PDF the
XmlScanner::getInstance()
is called many times:A new
getInstance()
is called before the__destruct()
of the previous one, causing thepreviousLibxmlDisableEntityLoaderValue
to containfalse
even when the original value wastrue
.My solution was to share
$previousLibxmlDisableEntityLoaderValue
accross all instances, and be sure to not overwrite the original value.