Skip to content

Commit

Permalink
Use libxml_disable_entity_loader only for older versions of libxml
Browse files Browse the repository at this point in the history
  • Loading branch information
sanmai committed Nov 12, 2020
1 parent f3c8b92 commit 5fcf562
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/XmlDeserializationVisitor.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,9 @@ public function prepare($data)
$previous = libxml_use_internal_errors(true);
libxml_clear_errors();

$previousEntityLoaderState = @libxml_disable_entity_loader($this->disableExternalEntities);
if (\LIBXML_VERSION < 20900) {
$previousEntityLoaderState = libxml_disable_entity_loader($this->disableExternalEntities);
}

if (false !== stripos($data, '<!doctype')) {
$internalSubset = $this->getDomDocumentTypeEntitySubset($data);
Expand All @@ -92,7 +94,10 @@ public function prepare($data)
$doc = simplexml_load_string($data, 'SimpleXMLElement', $this->options);

libxml_use_internal_errors($previous);
@libxml_disable_entity_loader($previousEntityLoaderState);

if (\LIBXML_VERSION < 20900) {
libxml_disable_entity_loader($previousEntityLoaderState);
}

if (false === $doc) {
throw new XmlErrorException(libxml_get_last_error());
Expand Down

0 comments on commit 5fcf562

Please sign in to comment.