Skip to content

Commit ce3cb65

Browse files
authored
Merge pull request #3092 from iansltx/backport-libxml-php8-compat
Don't use libxml_disable_entity_loader when deprecated
2 parents 13f305f + eea18b9 commit ce3cb65

File tree

1 file changed

+17
-4
lines changed

1 file changed

+17
-4
lines changed

Slim/Http/Request.php

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -205,10 +205,10 @@ public function __construct(
205205
});
206206

207207
$this->registerMediaTypeParser('application/xml', function ($input) {
208-
$backup = libxml_disable_entity_loader(true);
208+
$backup = self::disableXmlEntityLoader(true);
209209
$backup_errors = libxml_use_internal_errors(true);
210210
$result = simplexml_load_string($input);
211-
libxml_disable_entity_loader($backup);
211+
self::disableXmlEntityLoader($backup);
212212
libxml_clear_errors();
213213
libxml_use_internal_errors($backup_errors);
214214
if ($result === false) {
@@ -218,10 +218,10 @@ public function __construct(
218218
});
219219

220220
$this->registerMediaTypeParser('text/xml', function ($input) {
221-
$backup = libxml_disable_entity_loader(true);
221+
$backup = self::disableXmlEntityLoader(true);
222222
$backup_errors = libxml_use_internal_errors(true);
223223
$result = simplexml_load_string($input);
224-
libxml_disable_entity_loader($backup);
224+
self::disableXmlEntityLoader($backup);
225225
libxml_clear_errors();
226226
libxml_use_internal_errors($backup_errors);
227227
if ($result === false) {
@@ -1208,4 +1208,17 @@ public function getParams(array $only = null)
12081208

12091209
return $params;
12101210
}
1211+
1212+
private static function disableXmlEntityLoader($disable)
1213+
{
1214+
if (\LIBXML_VERSION >= 20900) {
1215+
// libxml >= 2.9.0 disables entity loading by default, so it is
1216+
// safe to skip the real call (deprecated in PHP 8).
1217+
return true;
1218+
}
1219+
1220+
// @codeCoverageIgnoreStart
1221+
return libxml_disable_entity_loader($disable);
1222+
// @codeCoverageIgnoreEnd
1223+
}
12111224
}

0 commit comments

Comments
 (0)