Skip to content

Commit

Permalink
Merge pull request #3092 from iansltx/backport-libxml-php8-compat
Browse files Browse the repository at this point in the history
Don't use libxml_disable_entity_loader when deprecated
  • Loading branch information
l0gicgate authored Oct 2, 2021
2 parents 13f305f + eea18b9 commit ce3cb65
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions Slim/Http/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -205,10 +205,10 @@ public function __construct(
});

$this->registerMediaTypeParser('application/xml', function ($input) {
$backup = libxml_disable_entity_loader(true);
$backup = self::disableXmlEntityLoader(true);
$backup_errors = libxml_use_internal_errors(true);
$result = simplexml_load_string($input);
libxml_disable_entity_loader($backup);
self::disableXmlEntityLoader($backup);
libxml_clear_errors();
libxml_use_internal_errors($backup_errors);
if ($result === false) {
Expand All @@ -218,10 +218,10 @@ public function __construct(
});

$this->registerMediaTypeParser('text/xml', function ($input) {
$backup = libxml_disable_entity_loader(true);
$backup = self::disableXmlEntityLoader(true);
$backup_errors = libxml_use_internal_errors(true);
$result = simplexml_load_string($input);
libxml_disable_entity_loader($backup);
self::disableXmlEntityLoader($backup);
libxml_clear_errors();
libxml_use_internal_errors($backup_errors);
if ($result === false) {
Expand Down Expand Up @@ -1208,4 +1208,17 @@ public function getParams(array $only = null)

return $params;
}

private static function disableXmlEntityLoader($disable)
{
if (\LIBXML_VERSION >= 20900) {
// libxml >= 2.9.0 disables entity loading by default, so it is
// safe to skip the real call (deprecated in PHP 8).
return true;
}

// @codeCoverageIgnoreStart
return libxml_disable_entity_loader($disable);
// @codeCoverageIgnoreEnd
}
}

0 comments on commit ce3cb65

Please sign in to comment.