Skip to content

Commit adb48ad

Browse files
committed
[Finder] Fixed leading/trailing / in filename
Without this patch, we go this: ``` --- Expected +++ Actual @@ @@ Array ( - 0 => '/tmp/symfony_finder/foo bar' - 1 => '/tmp/symfony_finder/foo/bar.tmp' - 2 => '/tmp/symfony_finder/test.php' - 3 => '/tmp/symfony_finder/test.py' + 0 => '///tmp/symfony_finder///foo bar' + 1 => '///tmp/symfony_finder///foo/bar.tmp' + 2 => '///tmp/symfony_finder///test.php' + 3 => '///tmp/symfony_finder///test.py' ) ```
1 parent 87bbe5e commit adb48ad

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

src/Symfony/Component/Finder/Finder.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -633,6 +633,8 @@ public function in($dirs)
633633
}
634634
}
635635

636+
$resolvedDirs = array_map('realpath', $resolvedDirs);
637+
636638
$this->dirs = array_merge($this->dirs, $resolvedDirs);
637639

638640
return $this;

src/Symfony/Component/Finder/Tests/FinderTest.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,21 @@ public function testFiles()
4545
$finder->files();
4646
$finder->directories();
4747
$finder->files();
48+
4849
$this->assertIterator($this->toAbsolute(array('foo/bar.tmp', 'test.php', 'test.py', 'foo bar')), $finder->in(self::$tmpDir)->getIterator());
4950
}
5051

52+
public function testRemoveTrailingSlash()
53+
{
54+
$finder = $this->buildFinder();
55+
56+
$expected = $this->toAbsolute(array('foo/bar.tmp', 'test.php', 'test.py', 'foo bar'));
57+
$in = realpath(self::$tmpDir);
58+
$in = '//'.realpath(self::$tmpDir).'//';
59+
60+
$this->assertIterator($expected, $finder->in($in)->files()->getIterator());
61+
}
62+
5163
public function testDepth()
5264
{
5365
$finder = $this->buildFinder();

0 commit comments

Comments
 (0)