Skip to content

Commit 979e3a5

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 8c8d476 + ceed3ca commit 979e3a5

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

Loader/XliffFileLoader.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,10 +142,16 @@ private function parseFile($file)
142142
$source = file_get_contents(__DIR__.'/schema/dic/xliff-core/xliff-core-1.2-strict.xsd');
143143
$source = str_replace('http://www.w3.org/2001/xml.xsd', $location, $source);
144144

145+
$disableEntities = libxml_disable_entity_loader(false);
146+
145147
if (!@$dom->schemaValidateSource($source)) {
148+
libxml_disable_entity_loader($disableEntities);
149+
146150
throw new InvalidResourceException(sprintf('Invalid resource provided: "%s"; Errors: %s', $file, implode("\n", $this->getXmlErrors($internalErrors))));
147151
}
148152

153+
libxml_disable_entity_loader($disableEntities);
154+
149155
$dom->normalizeDocument();
150156

151157
libxml_clear_errors();

Tests/Loader/XliffFileLoaderTest.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,20 @@ public function testLoadWithInternalErrorsEnabled()
4646
libxml_use_internal_errors($internalErrors);
4747
}
4848

49+
public function testLoadWithExternalEntitiesDisabled()
50+
{
51+
$disableEntities = libxml_disable_entity_loader(true);
52+
53+
$loader = new XliffFileLoader();
54+
$resource = __DIR__.'/../fixtures/resources.xlf';
55+
$catalogue = $loader->load($resource, 'en', 'domain1');
56+
57+
libxml_disable_entity_loader($disableEntities);
58+
59+
$this->assertEquals('en', $catalogue->getLocale());
60+
$this->assertEquals(array(new FileResource($resource)), $catalogue->getResources());
61+
}
62+
4963
public function testLoadWithResname()
5064
{
5165
$loader = new XliffFileLoader();

0 commit comments

Comments
 (0)