Skip to content

Commit

Permalink
Merge branch '3.4' into 4.4
Browse files Browse the repository at this point in the history
* 3.4:
  Add Tagalog translations for validator messages 94, 95, 96 and 99
  PHPUnit's assertContains() performs strict comparisons now.
  [ClassLoader][Routing] Fix namespace parsing on php 8.
  Fix deprecated libxml_disable_entity_loader
  Made reference to PHPUnit\Util\XML::loadfile php5-compatible.
  [Validator] Add missing translations for german and vietnamese
  Modernized deprecated PHPUnit assertion calls
  [Console] The message of "class not found" errors has changed in php 8.
  The PHPUnit\Util\XML class has been removed in PHPUnit 9.3.
  [Console] Make sure we pass a numeric array of arguments to call_user_func_array().
  [Serializer] Fix that it will never reach DOMNode
  [Validator] sync translations
  [VarDumper] Improve previous fix on light array coloration
  [Cache] Fix #37667
  • Loading branch information
fabpot committed Aug 10, 2020
2 parents b1d8f0d + 801a3bb commit 043bf86
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 10 deletions.
17 changes: 10 additions & 7 deletions Tests/Util/XmlUtilsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public function testLoadFile()
XmlUtils::loadFile($fixtures.'valid.xml', [$mock, 'validate']);
$this->fail();
} catch (\InvalidArgumentException $e) {
$this->assertRegExp('/The XML file ".+" is not valid\./', $e->getMessage());
$this->assertMatchesRegularExpression('/The XML file ".+" is not valid\./', $e->getMessage());
}

$this->assertInstanceOf('DOMDocument', XmlUtils::loadFile($fixtures.'valid.xml', [$mock, 'validate']));
Expand Down Expand Up @@ -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) {
Expand All @@ -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');
Expand Down
12 changes: 9 additions & 3 deletions Util/XmlUtils.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,21 +51,27 @@ 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)));
}

$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) {
Expand Down

0 comments on commit 043bf86

Please sign in to comment.