[Config][DependencyInjection] Uniformize trailing slash handling
This commit is contained in:
parent
2dd8445198
commit
dc50aa3b55
|
@ -82,8 +82,8 @@ abstract class FileLoader extends Loader
|
|||
$excluded = [];
|
||||
foreach ((array) $exclude as $pattern) {
|
||||
foreach ($this->glob($pattern, true, $_, false, true) as $path => $info) {
|
||||
// normalize Windows slashes
|
||||
$excluded[str_replace('\\', '/', $path)] = true;
|
||||
// normalize Windows slashes and remove trailing slashes
|
||||
$excluded[rtrim(str_replace('\\', '/', $path), '/')] = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -127,6 +127,28 @@ class FileLoaderTest extends TestCase
|
|||
$this->assertCount(2, $loadedFiles);
|
||||
$this->assertNotContains('ExcludeFile.txt', $loadedFiles);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider excludeTrailingSlashConsistencyProvider
|
||||
*/
|
||||
public function testExcludeTrailingSlashConsistency(string $exclude)
|
||||
{
|
||||
$loader = new TestFileLoader(new FileLocator(__DIR__.'/../Fixtures'));
|
||||
$loadedFiles = $loader->import('ExcludeTrailingSlash/*', null, false, null, $exclude);
|
||||
$this->assertCount(2, $loadedFiles);
|
||||
$this->assertNotContains('baz.txt', $loadedFiles);
|
||||
}
|
||||
|
||||
public function excludeTrailingSlashConsistencyProvider(): iterable
|
||||
{
|
||||
yield [__DIR__.'/../Fixtures/Exclude/ExcludeToo/'];
|
||||
yield [__DIR__.'/../Fixtures/Exclude/ExcludeToo'];
|
||||
yield [__DIR__.'/../Fixtures/Exclude/ExcludeToo/*'];
|
||||
yield [__DIR__.'/../Fixtures/*/ExcludeToo'];
|
||||
yield [__DIR__.'/../Fixtures/*/ExcludeToo/'];
|
||||
yield [__DIR__.'/../Fixtures/Exclude/ExcludeToo/*'];
|
||||
yield [__DIR__.'/../Fixtures/Exclude/ExcludeToo/AnotheExcludedFile.txt'];
|
||||
}
|
||||
}
|
||||
|
||||
class TestFileLoader extends FileLoader
|
||||
|
|
|
@ -177,6 +177,7 @@ class GlobResourceTest extends TestCase
|
|||
|
||||
$expected = [
|
||||
$dir.'/Exclude/ExcludeToo/AnotheExcludedFile.txt',
|
||||
$dir.'/ExcludeTrailingSlash/exclude/baz.txt',
|
||||
$dir.'/foo.xml',
|
||||
];
|
||||
|
||||
|
|
|
@ -166,8 +166,8 @@ abstract class FileLoader extends BaseFileLoader
|
|||
$excludePrefix = $resource->getPrefix();
|
||||
}
|
||||
|
||||
// normalize Windows slashes
|
||||
$excludePaths[str_replace('\\', '/', $path)] = true;
|
||||
// normalize Windows slashes and remove trailing slashes
|
||||
$excludePaths[rtrim(str_replace('\\', '/', $path), '/')] = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -239,6 +239,35 @@ class FileLoaderTest extends TestCase
|
|||
'yaml/*'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider excludeTrailingSlashConsistencyProvider
|
||||
*/
|
||||
public function testExcludeTrailingSlashConsistency(string $exclude)
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
$loader = new TestFileLoader($container, new FileLocator(self::$fixturesPath.'/Fixtures'));
|
||||
$loader->registerClasses(
|
||||
new Definition(),
|
||||
'Symfony\Component\DependencyInjection\Tests\Fixtures\Prototype\\',
|
||||
'Prototype/*',
|
||||
$exclude
|
||||
);
|
||||
|
||||
$this->assertTrue($container->has(Foo::class));
|
||||
$this->assertFalse($container->has(DeeperBaz::class));
|
||||
}
|
||||
|
||||
public function excludeTrailingSlashConsistencyProvider(): iterable
|
||||
{
|
||||
yield ['Prototype/OtherDir/AnotherSub/'];
|
||||
yield ['Prototype/OtherDir/AnotherSub'];
|
||||
yield ['Prototype/OtherDir/AnotherSub/*'];
|
||||
yield ['Prototype/*/AnotherSub'];
|
||||
yield ['Prototype/*/AnotherSub/'];
|
||||
yield ['Prototype/*/AnotherSub/*'];
|
||||
yield ['Prototype/OtherDir/AnotherSub/DeeperBaz.php'];
|
||||
}
|
||||
}
|
||||
|
||||
class TestFileLoader extends FileLoader
|
||||
|
|
Reference in New Issue