Skip to content

Commit

Permalink
bug #18915 [DependencyInjection] force enabling the external XML enti…
Browse files Browse the repository at this point in the history
…ty loaders (xabbuh)

This PR was merged into the 2.7 branch.

Discussion
----------

[DependencyInjection] force enabling the external XML entity loaders

| Q             | A
| ------------- | ---
| Branch?       | 2.7
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #18876, #18908
| License       | MIT
| Doc PR        |

Commits
-------

12b5509 force enabling the external XML entity loaders
  • Loading branch information
fabpot committed Jun 13, 2016
2 parents 11f3039 + 12b5509 commit 3f192dc
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 1 deletion.
Expand Up @@ -315,7 +315,6 @@ private function processAnonymousServices(\DOMDocument $xml, $file)
foreach ($definitions as $id => $def) {
list($domElement, $file, $wild) = $def;


if (null !== $definition = $this->parseDefinition($domElement, $file)) {
$this->container->setDefinition($id, $definition);
}
Expand Down Expand Up @@ -485,7 +484,9 @@ public function validateSchema(\DOMDocument $dom)
EOF
;

$disableEntities = libxml_disable_entity_loader(false);
$valid = @$dom->schemaValidateSource($source);
libxml_disable_entity_loader($disableEntities);

foreach ($tmpfiles as $tmpfile) {
@unlink($tmpfile);
Expand Down
Expand Up @@ -84,6 +84,19 @@ public function testParseFile()
$this->assertInstanceOf('DOMDocument', $xml, '->parseFileToDOM() returns an SimpleXMLElement object');
}

public function testLoadWithExternalEntitiesDisabled()
{
$disableEntities = libxml_disable_entity_loader(true);

$containerBuilder = new ContainerBuilder();
$loader = new XmlFileLoader($containerBuilder, new FileLocator(self::$fixturesPath.'/xml'));
$loader->load('services2.xml');

libxml_disable_entity_loader($disableEntities);

$this->assertTrue(count($containerBuilder->getParameterBag()->all()) > 0, 'Parameters can be read from the config file.');
}

public function testLoadParameters()
{
$container = new ContainerBuilder();
Expand Down
6 changes: 6 additions & 0 deletions src/Symfony/Component/Translation/Loader/XliffFileLoader.php
Expand Up @@ -142,10 +142,16 @@ private function parseFile($file)
$source = file_get_contents(__DIR__.'/schema/dic/xliff-core/xliff-core-1.2-strict.xsd');
$source = str_replace('http://www.w3.org/2001/xml.xsd', $location, $source);

$disableEntities = libxml_disable_entity_loader(false);

if (!@$dom->schemaValidateSource($source)) {
libxml_disable_entity_loader($disableEntities);

throw new InvalidResourceException(sprintf('Invalid resource provided: "%s"; Errors: %s', $file, implode("\n", $this->getXmlErrors($internalErrors))));
}

libxml_disable_entity_loader($disableEntities);

$dom->normalizeDocument();

libxml_clear_errors();
Expand Down
Expand Up @@ -46,6 +46,20 @@ public function testLoadWithInternalErrorsEnabled()
libxml_use_internal_errors($internalErrors);
}

public function testLoadWithExternalEntitiesDisabled()
{
$disableEntities = libxml_disable_entity_loader(true);

$loader = new XliffFileLoader();
$resource = __DIR__.'/../fixtures/resources.xlf';
$catalogue = $loader->load($resource, 'en', 'domain1');

libxml_disable_entity_loader($disableEntities);

$this->assertEquals('en', $catalogue->getLocale());
$this->assertEquals(array(new FileResource($resource)), $catalogue->getResources());
}

public function testLoadWithResname()
{
$loader = new XliffFileLoader();
Expand Down

0 comments on commit 3f192dc

Please sign in to comment.