Skip to content

Commit 8b8716d

Browse files
committed
bug #18915 [DependencyInjection] force enabling the external XML entity 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
2 parents 3d4146f + 4ac151e commit 8b8716d

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

Loader/XmlFileLoader.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,6 @@ private function processAnonymousServices(\DOMDocument $xml, $file)
315315
foreach ($definitions as $id => $def) {
316316
list($domElement, $file, $wild) = $def;
317317

318-
319318
if (null !== $definition = $this->parseDefinition($domElement, $file)) {
320319
$this->container->setDefinition($id, $definition);
321320
}
@@ -485,7 +484,9 @@ public function validateSchema(\DOMDocument $dom)
485484
EOF
486485
;
487486

487+
$disableEntities = libxml_disable_entity_loader(false);
488488
$valid = @$dom->schemaValidateSource($source);
489+
libxml_disable_entity_loader($disableEntities);
489490

490491
foreach ($tmpfiles as $tmpfile) {
491492
@unlink($tmpfile);

Tests/Loader/XmlFileLoaderTest.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,19 @@ public function testParseFile()
8484
$this->assertInstanceOf('DOMDocument', $xml, '->parseFileToDOM() returns an SimpleXMLElement object');
8585
}
8686

87+
public function testLoadWithExternalEntitiesDisabled()
88+
{
89+
$disableEntities = libxml_disable_entity_loader(true);
90+
91+
$containerBuilder = new ContainerBuilder();
92+
$loader = new XmlFileLoader($containerBuilder, new FileLocator(self::$fixturesPath.'/xml'));
93+
$loader->load('services2.xml');
94+
95+
libxml_disable_entity_loader($disableEntities);
96+
97+
$this->assertTrue(count($containerBuilder->getParameterBag()->all()) > 0, 'Parameters can be read from the config file.');
98+
}
99+
87100
public function testLoadParameters()
88101
{
89102
$container = new ContainerBuilder();

0 commit comments

Comments
 (0)