23412 Stop treating multiline resources as globs

This commit is contained in:
Michael Käfer 2020-11-22 23:57:50 +01:00
parent b60bb6e2d6
commit 1e3baad386
2 changed files with 26 additions and 1 deletions

View File

@ -78,7 +78,7 @@ abstract class FileLoader extends Loader
}
$exclude = \func_num_args() >= 5 ? func_get_arg(4) : null;
if (\is_string($resource) && \strlen($resource) !== $i = strcspn($resource, '*?{[')) {
if (\is_string($resource) && \strlen($resource) !== ($i = strcspn($resource, '*?{[')) && false === strpos($resource, "\n")) {
$excluded = [];
foreach ((array) $exclude as $pattern) {
foreach ($this->glob($pattern, true, $_, false, true) as $path => $info) {

View File

@ -77,6 +77,31 @@ class FileLoaderTest extends TestCase
$this->assertSame('[foo]', $loader->import('[foo]'));
}
public function testImportWithGlobLikeResourceWhichContainsSlashes()
{
$locatorMock = $this->getMockBuilder('Symfony\Component\Config\FileLocatorInterface')->getMock();
$locatorMock->expects($this->once())->method('locate')->willReturn('');
$loader = new TestFileLoader($locatorMock);
$this->assertNull($loader->import('foo/bar[foo]'));
}
public function testImportWithGlobLikeResourceWhichContainsMultipleLines()
{
$locatorMock = $this->getMockBuilder('Symfony\Component\Config\FileLocatorInterface')->getMock();
$loader = new TestFileLoader($locatorMock);
$this->assertSame("foo\nfoobar[foo]", $loader->import("foo\nfoobar[foo]"));
}
public function testImportWithGlobLikeResourceWhichContainsSlashesAndMultipleLines()
{
$locatorMock = $this->getMockBuilder('Symfony\Component\Config\FileLocatorInterface')->getMock();
$loader = new TestFileLoader($locatorMock);
$this->assertSame("foo\nfoo/bar[foo]", $loader->import("foo\nfoo/bar[foo]"));
}
public function testImportWithNoGlobMatch()
{
$locatorMock = $this->getMockBuilder('Symfony\Component\Config\FileLocatorInterface')->getMock();