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

[Config][DependencyInjection] Uniformize trailing slash handling #40917

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 7, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
[Config][DependencyInjection] Uniformize trailing slash handling
  • Loading branch information
dunglas authored and nicolas-grekas committed May 7, 2021
commit dc50aa3b55b5504f55a8faf8ccd115561cb14315
4 changes: 2 additions & 2 deletions 4 src/Symfony/Component/Config/Loader/FileLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,8 @@ public function import($resource, $type = null, $ignoreErrors = false, $sourceRe
$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;
}
}

Expand Down
Empty file.
Empty file.
22 changes: 22 additions & 0 deletions 22 src/Symfony/Component/Config/Tests/Loader/FileLoaderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,28 @@ public function testImportWithExclude()
$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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ public function testBraceFallback()

$expected = [
$dir.'/Exclude/ExcludeToo/AnotheExcludedFile.txt',
$dir.'/ExcludeTrailingSlash/exclude/baz.txt',
$dir.'/foo.xml',
];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,8 +166,8 @@ private function findClasses(string $namespace, string $pattern, array $excludeP
$excludePrefix = $resource->getPrefix();
}

// normalize Windows slashes
$excludePaths[str_replace('\\', '/', $path)] = true;
// normalize Windows slashes and remove trailing slashes
$excludePaths[rtrim(str_replace('\\', '/', $path), '/')] = true;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,35 @@ public function testRegisterClassesWithIncompatibleExclude()
'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
Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.