Skip to content

Commit

Permalink
libxml_disable_entity_loader() is deprecated in PHP 8
Browse files Browse the repository at this point in the history
  • Loading branch information
alexpott committed Sep 30, 2020
1 parent 16d251b commit ee3874f
Showing 1 changed file with 20 additions and 8 deletions.
28 changes: 20 additions & 8 deletions src/Reader/Reader.php
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,9 @@ public static function importString($string)
}

$libxmlErrflag = libxml_use_internal_errors(true);
$oldValue = libxml_disable_entity_loader(true);
if (LIBXML_VERSION < 20900) {
$oldValue = libxml_disable_entity_loader(true);
}
$dom = new DOMDocument();
$status = $dom->loadXML(trim($string));
foreach ($dom->childNodes as $child) {
Expand All @@ -325,7 +327,9 @@ public static function importString($string)
);
}
}
libxml_disable_entity_loader($oldValue);
if (LIBXML_VERSION < 20900) {
libxml_disable_entity_loader($oldValue);
}
libxml_use_internal_errors($libxmlErrflag);

if (! $status) {
Expand Down Expand Up @@ -395,10 +399,14 @@ public static function findFeedLinks($uri)
}
$responseHtml = $response->getBody();
$libxmlErrflag = libxml_use_internal_errors(true);
$oldValue = libxml_disable_entity_loader(true);
if (LIBXML_VERSION < 20900) {
$oldValue = libxml_disable_entity_loader(true);
}
$dom = new DOMDocument();
$status = $dom->loadHTML(trim($responseHtml));
libxml_disable_entity_loader($oldValue);
if (LIBXML_VERSION < 20900) {
libxml_disable_entity_loader($oldValue);
}
libxml_use_internal_errors($libxmlErrflag);
if (! $status) {
// Build error message
Expand Down Expand Up @@ -435,17 +443,21 @@ public static function detectType($feed, $specOnly = false)
} elseif (is_string($feed) && ! empty($feed)) {
ErrorHandler::start(E_NOTICE | E_WARNING);
ini_set('track_errors', 1);
$oldValue = libxml_disable_entity_loader(true);
$dom = new DOMDocument();
$status = $dom->loadXML($feed);
if (LIBXML_VERSION < 20900) {
$oldValue = libxml_disable_entity_loader(true);
}
$dom = new DOMDocument();
$status = $dom->loadXML($feed);
foreach ($dom->childNodes as $child) {
if ($child->nodeType === XML_DOCUMENT_TYPE_NODE) {
throw new Exception\InvalidArgumentException(
'Invalid XML: Detected use of illegal DOCTYPE'
);
}
}
libxml_disable_entity_loader($oldValue);
if (LIBXML_VERSION < 20900) {
libxml_disable_entity_loader($oldValue);
}
ini_restore('track_errors');
ErrorHandler::stop();
if (! $status) {
Expand Down

0 comments on commit ee3874f

Please sign in to comment.