From 55c9f1b8e1054435a2fbb444843d276721b6ce79 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Deruss=C3=A9?= Date: Fri, 7 Aug 2020 11:40:57 +0200 Subject: [PATCH] Fix deprecated libxml_disable_entity_loader --- Tests/Util/XmlUtilsTest.php | 15 +++++++++------ Util/XmlUtils.php | 12 +++++++++--- 2 files changed, 18 insertions(+), 9 deletions(-) diff --git a/Tests/Util/XmlUtilsTest.php b/Tests/Util/XmlUtilsTest.php index 2aecdf825..c964c525e 100644 --- a/Tests/Util/XmlUtilsTest.php +++ b/Tests/Util/XmlUtilsTest.php @@ -199,7 +199,9 @@ public function testLoadEmptyXmlFile() // test for issue https://github.com/symfony/symfony/issues/9731 public function testLoadWrongEmptyXMLWithErrorHandler() { - $originalDisableEntities = libxml_disable_entity_loader(false); + if (LIBXML_VERSION < 20900) { + $originalDisableEntities = libxml_disable_entity_loader(false); + } $errorReporting = error_reporting(-1); set_error_handler(function ($errno, $errstr) { @@ -219,12 +221,13 @@ public function testLoadWrongEmptyXMLWithErrorHandler() error_reporting($errorReporting); } - $disableEntities = libxml_disable_entity_loader(true); - libxml_disable_entity_loader($disableEntities); - - libxml_disable_entity_loader($originalDisableEntities); + if (LIBXML_VERSION < 20900) { + $disableEntities = libxml_disable_entity_loader(true); + libxml_disable_entity_loader($disableEntities); - $this->assertFalse($disableEntities); + libxml_disable_entity_loader($originalDisableEntities); + $this->assertFalse($disableEntities); + } // should not throw an exception XmlUtils::loadFile(__DIR__.'/../Fixtures/Util/valid.xml', __DIR__.'/../Fixtures/Util/schema.xsd'); diff --git a/Util/XmlUtils.php b/Util/XmlUtils.php index c925f315e..203741ad1 100644 --- a/Util/XmlUtils.php +++ b/Util/XmlUtils.php @@ -51,13 +51,17 @@ public static function parse($content, $schemaOrCallable = null) } $internalErrors = libxml_use_internal_errors(true); - $disableEntities = libxml_disable_entity_loader(true); + if (LIBXML_VERSION < 20900) { + $disableEntities = libxml_disable_entity_loader(true); + } libxml_clear_errors(); $dom = new \DOMDocument(); $dom->validateOnParse = true; if (!$dom->loadXML($content, LIBXML_NONET | (\defined('LIBXML_COMPACT') ? LIBXML_COMPACT : 0))) { - libxml_disable_entity_loader($disableEntities); + if (LIBXML_VERSION < 20900) { + libxml_disable_entity_loader($disableEntities); + } throw new XmlParsingException(implode("\n", static::getXmlErrors($internalErrors))); } @@ -65,7 +69,9 @@ public static function parse($content, $schemaOrCallable = null) $dom->normalizeDocument(); libxml_use_internal_errors($internalErrors); - libxml_disable_entity_loader($disableEntities); + if (LIBXML_VERSION < 20900) { + libxml_disable_entity_loader($disableEntities); + } foreach ($dom->childNodes as $child) { if (XML_DOCUMENT_TYPE_NODE === $child->nodeType) {