Skip to content

Commit 92a4b72

Browse files
committed
bug #57895 [Finder] do not duplicate directory separators (xabbuh)
This PR was merged into the 5.4 branch. Discussion ---------- [Finder] do not duplicate directory separators | Q | A | ------------- | --- | Branch? | 5.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | Issues | Fix #54352 | License | MIT Commits ------- a449a85 do not duplicate directory separators
2 parents 093076d + a449a85 commit 92a4b72

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

src/Symfony/Component/Finder/Iterator/RecursiveDirectoryIterator.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,9 @@ public function current()
7070
$subPathname .= $this->directorySeparator;
7171
}
7272
$subPathname .= $this->getFilename();
73+
$basePath = $this->rootPath;
7374

74-
if ('/' !== $basePath = $this->rootPath) {
75+
if ('/' !== $basePath && !str_ends_with($basePath, $this->directorySeparator)) {
7576
$basePath .= $this->directorySeparator;
7677
}
7778

src/Symfony/Component/Finder/Tests/Iterator/RecursiveDirectoryIteratorTest.php

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,4 +55,31 @@ public function testSeekOnFtp()
5555

5656
$this->assertEquals($contains, $actual);
5757
}
58+
59+
public function testTrailingDirectorySeparatorIsStripped()
60+
{
61+
$fixturesDirectory = __DIR__ . '/../Fixtures/';
62+
$actual = [];
63+
64+
foreach (new RecursiveDirectoryIterator($fixturesDirectory, RecursiveDirectoryIterator::SKIP_DOTS) as $file) {
65+
$actual[] = $file->getPathname();
66+
}
67+
68+
sort($actual);
69+
70+
$expected = [
71+
$fixturesDirectory.'.dot',
72+
$fixturesDirectory.'A',
73+
$fixturesDirectory.'copy',
74+
$fixturesDirectory.'dolor.txt',
75+
$fixturesDirectory.'gitignore',
76+
$fixturesDirectory.'ipsum.txt',
77+
$fixturesDirectory.'lorem.txt',
78+
$fixturesDirectory.'one',
79+
$fixturesDirectory.'r+e.gex[c]a(r)s',
80+
$fixturesDirectory.'with space',
81+
];
82+
83+
$this->assertEquals($expected, $actual);
84+
}
5885
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy