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

Commit 05e6278

Browse filesBrowse files
committed
[DependencyInjection][Config] Uniformize trailing slash handling
1 parent 2dd8445 commit 05e6278
Copy full SHA for 05e6278

File tree

7 files changed

+56
-4
lines changed
Filter options

7 files changed

+56
-4
lines changed

‎src/Symfony/Component/Config/Loader/FileLoader.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Config/Loader/FileLoader.php
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,8 @@ public function import($resource, $type = null, $ignoreErrors = false, $sourceRe
8282
$excluded = [];
8383
foreach ((array) $exclude as $pattern) {
8484
foreach ($this->glob($pattern, true, $_, false, true) as $path => $info) {
85-
// normalize Windows slashes
86-
$excluded[str_replace('\\', '/', $path)] = true;
85+
// normalize Windows slashes and remove trailing slashes
86+
$excluded[rtrim(str_replace('\\', '/', $path), '/')] = true;
8787
}
8888
}
8989

‎src/Symfony/Component/Config/Tests/Fixtures/ExcludeTrailingSlash/bar.txt

Copy file name to clipboardExpand all lines: src/Symfony/Component/Config/Tests/Fixtures/ExcludeTrailingSlash/bar.txt
Whitespace-only changes.

‎src/Symfony/Component/Config/Tests/Fixtures/ExcludeTrailingSlash/exclude/baz.txt

Copy file name to clipboardExpand all lines: src/Symfony/Component/Config/Tests/Fixtures/ExcludeTrailingSlash/exclude/baz.txt
Whitespace-only changes.

‎src/Symfony/Component/Config/Tests/Fixtures/ExcludeTrailingSlash/foo.txt

Copy file name to clipboardExpand all lines: src/Symfony/Component/Config/Tests/Fixtures/ExcludeTrailingSlash/foo.txt
Whitespace-only changes.

‎src/Symfony/Component/Config/Tests/Loader/FileLoaderTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Config/Tests/Loader/FileLoaderTest.php
+23Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,29 @@ public function testImportWithExclude()
127127
$this->assertCount(2, $loadedFiles);
128128
$this->assertNotContains('ExcludeFile.txt', $loadedFiles);
129129
}
130+
131+
132+
/**
133+
* @dataProvider excludeTrailingSlashConsistencyProvider
134+
*/
135+
public function testExcludeTrailingSlashConsistency(string $exclude): void
136+
{
137+
$loader = new TestFileLoader(new FileLocator(__DIR__.'/../Fixtures'));
138+
$loadedFiles = $loader->import('ExcludeTrailingSlash/*', null, false, null, $exclude);
139+
$this->assertCount(2, $loadedFiles);
140+
$this->assertNotContains('baz.txt', $loadedFiles);
141+
}
142+
143+
public function excludeTrailingSlashConsistencyProvider(): iterable
144+
{
145+
yield [__DIR__.'/../Fixtures/Exclude/ExcludeToo/'];
146+
yield [__DIR__.'/../Fixtures/Exclude/ExcludeToo'];
147+
yield [__DIR__.'/../Fixtures/Exclude/ExcludeToo/*'];
148+
yield [__DIR__.'/../Fixtures/*/ExcludeToo'];
149+
yield [__DIR__.'/../Fixtures/*/ExcludeToo/'];
150+
yield [__DIR__.'/../Fixtures/Exclude/ExcludeToo/*'];
151+
yield [__DIR__.'/../Fixtures/Exclude/ExcludeToo/AnotheExcludedFile.txt'];
152+
}
130153
}
131154

132155
class TestFileLoader extends FileLoader

‎src/Symfony/Component/DependencyInjection/Loader/FileLoader.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/DependencyInjection/Loader/FileLoader.php
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -166,8 +166,8 @@ private function findClasses(string $namespace, string $pattern, array $excludeP
166166
$excludePrefix = $resource->getPrefix();
167167
}
168168

169-
// normalize Windows slashes
170-
$excludePaths[str_replace('\\', '/', $path)] = true;
169+
// normalize Windows slashes and remove trailing slashes
170+
$excludePaths[rtrim(str_replace('\\', '/', $path), '/')] = true;
171171
}
172172
}
173173

‎src/Symfony/Component/DependencyInjection/Tests/Loader/FileLoaderTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/DependencyInjection/Tests/Loader/FileLoaderTest.php
+29Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,35 @@ public function testRegisterClassesWithIncompatibleExclude()
239239
'yaml/*'
240240
);
241241
}
242+
243+
/**
244+
* @dataProvider excludeTrailingSlashConsistencyProvider
245+
*/
246+
public function testExcludeTrailingSlashConsistency(string $exclude): void
247+
{
248+
$container = new ContainerBuilder();
249+
$loader = new TestFileLoader($container, new FileLocator(self::$fixturesPath.'/Fixtures'));
250+
$loader->registerClasses(
251+
new Definition(),
252+
'Symfony\Component\DependencyInjection\Tests\Fixtures\Prototype\\',
253+
'Prototype/*',
254+
$exclude
255+
);
256+
257+
$this->assertTrue($container->has(Foo::class));
258+
$this->assertFalse($container->has(DeeperBaz::class));
259+
}
260+
261+
public function excludeTrailingSlashConsistencyProvider(): iterable
262+
{
263+
yield ['Prototype/OtherDir/AnotherSub/'];
264+
yield ['Prototype/OtherDir/AnotherSub'];
265+
yield ['Prototype/OtherDir/AnotherSub/*'];
266+
yield ['Prototype/*/AnotherSub'];
267+
yield ['Prototype/*/AnotherSub/'];
268+
yield ['Prototype/*/AnotherSub/*'];
269+
yield ['Prototype/OtherDir/AnotherSub/DeeperBaz.php'];
270+
}
242271
}
243272

244273
class TestFileLoader extends FileLoader

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.