Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit e44a3f5

Browse filesBrowse files
committed
bug #35982 [DI] Fix XmlFileLoader bad error message (przemyslaw-bogusz)
This PR was squashed before being merged into the 3.4 branch. Discussion ---------- [DI] Fix XmlFileLoader bad error message | Q | A | ------------- | --- | Branch? | 3.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | Tickets | Fix #35886 | License | MIT | Doc PR | Commits ------- be7afc6 [DI] Fix XmlFileLoader bad error message
2 parents bd0bf52 + be7afc6 commit e44a3f5
Copy full SHA for e44a3f5

File tree

3 files changed

+37
-3
lines changed
Filter options

3 files changed

+37
-3
lines changed

‎src/Symfony/Component/Config/Tests/Fixtures/Util/not_readable.xml

Copy file name to clipboardExpand all lines: src/Symfony/Component/Config/Tests/Fixtures/Util/not_readable.xml
Whitespace-only changes.

‎src/Symfony/Component/Config/Tests/Util/XmlUtilsTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Config/Tests/Util/XmlUtilsTest.php
+27-2Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,31 @@ public function testLoadFile()
2020
{
2121
$fixtures = __DIR__.'/../Fixtures/Util/';
2222

23+
try {
24+
XmlUtils::loadFile($fixtures);
25+
$this->fail();
26+
} catch (\InvalidArgumentException $e) {
27+
$this->assertStringContainsString('is not a file', $e->getMessage());
28+
}
29+
30+
try {
31+
XmlUtils::loadFile($fixtures.'non_existing.xml');
32+
$this->fail();
33+
} catch (\InvalidArgumentException $e) {
34+
$this->assertStringContainsString('is not a file', $e->getMessage());
35+
}
36+
37+
try {
38+
if ('\\' === \DIRECTORY_SEPARATOR) {
39+
$this->markTestSkipped('chmod is not supported on Windows');
40+
}
41+
chmod($fixtures.'not_readable.xml', 000);
42+
XmlUtils::loadFile($fixtures.'not_readable.xml');
43+
$this->fail();
44+
} catch (\InvalidArgumentException $e) {
45+
$this->assertStringContainsString('is not readable', $e->getMessage());
46+
}
47+
2348
try {
2449
XmlUtils::loadFile($fixtures.'invalid.xml');
2550
$this->fail();
@@ -165,7 +190,7 @@ public function testLoadEmptyXmlFile()
165190
$file = __DIR__.'/../Fixtures/foo.xml';
166191

167192
$this->expectException('InvalidArgumentException');
168-
$this->expectExceptionMessage(sprintf('File %s does not contain valid XML, it is empty.', $file));
193+
$this->expectExceptionMessage(sprintf('File "%s" does not contain valid XML, it is empty.', $file));
169194

170195
XmlUtils::loadFile($file);
171196
}
@@ -186,7 +211,7 @@ public function testLoadWrongEmptyXMLWithErrorHandler()
186211
XmlUtils::loadFile($file);
187212
$this->fail('An exception should have been raised');
188213
} catch (\InvalidArgumentException $e) {
189-
$this->assertEquals(sprintf('File %s does not contain valid XML, it is empty.', $file), $e->getMessage());
214+
$this->assertEquals(sprintf('File "%s" does not contain valid XML, it is empty.', $file), $e->getMessage());
190215
}
191216
} finally {
192217
restore_error_handler();

‎src/Symfony/Component/Config/Util/XmlUtils.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Config/Util/XmlUtils.php
+10-1Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,9 +122,18 @@ public static function parse($content, $schemaOrCallable = null)
122122
*/
123123
public static function loadFile($file, $schemaOrCallable = null)
124124
{
125+
if (!is_file($file)) {
126+
throw new \InvalidArgumentException(sprintf('Resource "%s" is not a file.', $file));
127+
}
128+
129+
if (!is_readable($file)) {
130+
throw new \InvalidArgumentException(sprintf('File "%s" is not readable.', $file));
131+
}
132+
125133
$content = @file_get_contents($file);
134+
126135
if ('' === trim($content)) {
127-
throw new \InvalidArgumentException(sprintf('File %s does not contain valid XML, it is empty.', $file));
136+
throw new \InvalidArgumentException(sprintf('File "%s" does not contain valid XML, it is empty.', $file));
128137
}
129138

130139
try {

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.