From 1e3baad3865ab4b8d7d8f2504c416cb80b69ca6a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20K=C3=A4fer?= Date: Sun, 22 Nov 2020 23:57:50 +0100 Subject: [PATCH] 23412 Stop treating multiline resources as globs --- .../Component/Config/Loader/FileLoader.php | 2 +- .../Config/Tests/Loader/FileLoaderTest.php | 25 +++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/src/Symfony/Component/Config/Loader/FileLoader.php b/src/Symfony/Component/Config/Loader/FileLoader.php index e87230785b..c5988d2303 100644 --- a/src/Symfony/Component/Config/Loader/FileLoader.php +++ b/src/Symfony/Component/Config/Loader/FileLoader.php @@ -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) { diff --git a/src/Symfony/Component/Config/Tests/Loader/FileLoaderTest.php b/src/Symfony/Component/Config/Tests/Loader/FileLoaderTest.php index 6cf625e6c7..fc7a66c3b1 100644 --- a/src/Symfony/Component/Config/Tests/Loader/FileLoaderTest.php +++ b/src/Symfony/Component/Config/Tests/Loader/FileLoaderTest.php @@ -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();