Skip to content

Commit

Permalink
Don't use libxml_disable_entity_loader when deprecated
Browse files Browse the repository at this point in the history
Backports the important bit of slimphp/Slim-Http@4715329

You're on your own for full test suite to maintain PHP 5.5 compatibility, but this is the only thing I've run into where PHP 8 is a problem.
  • Loading branch information
iansltx committed Jun 29, 2021
1 parent 5850aae commit fa3d390
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 fa3d390

Please sign in to comment.