Skip to content

Commit e501c56

Browse files
bug #39142 [Config] Stop treating multiline resources as globs (michaelKaefer)
This PR was merged into the 4.4 branch. Discussion ---------- [Config] Stop treating multiline resources as globs | Q | A | ------------- | --- | Branch? | 4.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | Tickets | Fix #23412 | License | MIT Would fix the linked issue. In symfony/symfony#22938 it was suggested to enhance the glob-detection logic by detecting newlines. Cons: - it only solves an edge case - it is not possible to use a multiline glob (like `bar\nbaz*.txt`) as a resource anymore - maybe in another edge case this is needed Commits ------- 1e3baad386 23412 Stop treating multiline resources as globs
2 parents 65d9ef5 + 89645da commit e501c56

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

Loader/FileLoader.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ public function import($resource, $type = null, $ignoreErrors = false, $sourceRe
7878
}
7979
$exclude = \func_num_args() >= 5 ? func_get_arg(4) : null;
8080

81-
if (\is_string($resource) && \strlen($resource) !== $i = strcspn($resource, '*?{[')) {
81+
if (\is_string($resource) && \strlen($resource) !== ($i = strcspn($resource, '*?{[')) && false === strpos($resource, "\n")) {
8282
$excluded = [];
8383
foreach ((array) $exclude as $pattern) {
8484
foreach ($this->glob($pattern, true, $_, false, true) as $path => $info) {

Tests/Loader/FileLoaderTest.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,31 @@ public function testImportWithGlobLikeResource()
7777
$this->assertSame('[foo]', $loader->import('[foo]'));
7878
}
7979

80+
public function testImportWithGlobLikeResourceWhichContainsSlashes()
81+
{
82+
$locatorMock = $this->getMockBuilder('Symfony\Component\Config\FileLocatorInterface')->getMock();
83+
$locatorMock->expects($this->once())->method('locate')->willReturn('');
84+
$loader = new TestFileLoader($locatorMock);
85+
86+
$this->assertNull($loader->import('foo/bar[foo]'));
87+
}
88+
89+
public function testImportWithGlobLikeResourceWhichContainsMultipleLines()
90+
{
91+
$locatorMock = $this->getMockBuilder('Symfony\Component\Config\FileLocatorInterface')->getMock();
92+
$loader = new TestFileLoader($locatorMock);
93+
94+
$this->assertSame("foo\nfoobar[foo]", $loader->import("foo\nfoobar[foo]"));
95+
}
96+
97+
public function testImportWithGlobLikeResourceWhichContainsSlashesAndMultipleLines()
98+
{
99+
$locatorMock = $this->getMockBuilder('Symfony\Component\Config\FileLocatorInterface')->getMock();
100+
$loader = new TestFileLoader($locatorMock);
101+
102+
$this->assertSame("foo\nfoo/bar[foo]", $loader->import("foo\nfoo/bar[foo]"));
103+
}
104+
80105
public function testImportWithNoGlobMatch()
81106
{
82107
$locatorMock = $this->getMockBuilder('Symfony\Component\Config\FileLocatorInterface')->getMock();

0 commit comments

Comments
 (0)