Fixed bug that libxml_disable_entity_loader() has been deprecated as of PHP 8.0.0. (#3814)

close https://github.com/hyperf/hyperf/issues/3813

Co-authored-by: 李铭昕 <715557344@qq.com>
This commit is contained in:
沈唁 2021-07-16 09:49:15 +08:00 committed by GitHub
parent 21d245c1aa
commit 84679ddc0c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 3 deletions

View File

@ -87,3 +87,4 @@
- [#3788](https://github.com/hyperf/hyperf/pull/3788) Fixed type error when using `BladeCompiler::getRawPlaceholder()`. - [#3788](https://github.com/hyperf/hyperf/pull/3788) Fixed type error when using `BladeCompiler::getRawPlaceholder()`.
- [#3794](https://github.com/hyperf/hyperf/pull/3794) Fixed bug that `retry_interval` does not work for `rpc-multiplex`. - [#3794](https://github.com/hyperf/hyperf/pull/3794) Fixed bug that `retry_interval` does not work for `rpc-multiplex`.
- [#3798](https://github.com/hyperf/hyperf/pull/3798) Fixed bug that amqp consumer couldn't restart when rabbitmq server stopped. - [#3798](https://github.com/hyperf/hyperf/pull/3798) Fixed bug that amqp consumer couldn't restart when rabbitmq server stopped.
- [#3814](https://github.com/hyperf/hyperf/pull/3814) Fixed bug that `libxml_disable_entity_loader()` has been deprecated as of PHP 8.0.0.

View File

@ -49,9 +49,18 @@ class Xml
public static function toArray($xml) public static function toArray($xml)
{ {
$disableLibxmlEntityLoader = libxml_disable_entity_loader(true); // For PHP 8.0, libxml_disable_entity_loader() has been deprecated.
$respObject = simplexml_load_string($xml, 'SimpleXMLElement', LIBXML_NOCDATA | LIBXML_NOERROR); // As libxml 2.9.0 is now required, external entity loading is guaranteed to be disabled by default.
libxml_disable_entity_loader($disableLibxmlEntityLoader); // And this function is no longer needed to protect against XXE attacks, unless the (still vulnerable). LIBXML_NOENT is used.
// In that case, it is recommended to refactor the code using libxml_set_external_entity_loader() to suppress loading of external entities.
if (\PHP_VERSION_ID < 80000) {
$disableLibxmlEntityLoader = libxml_disable_entity_loader(true);
$respObject = simplexml_load_string($xml, 'SimpleXMLElement', LIBXML_NOCDATA | LIBXML_NOERROR);
libxml_disable_entity_loader($disableLibxmlEntityLoader);
} else {
$respObject = simplexml_load_string($xml, 'SimpleXMLElement', LIBXML_NOCDATA | LIBXML_NOERROR);
}
if ($respObject === false) { if ($respObject === false) {
throw new InvalidArgumentException('Syntax error.'); throw new InvalidArgumentException('Syntax error.');
} }