Skip to content

Commit 4ac151e

Browse files
committed
force enabling the external XML entity loaders
1 parent 99cd6fd commit 4ac151e

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)