Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 514cd9d

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 514cd9d

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

src/Symfony/Component/Finder/SplFileInfo.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ class SplFileInfo extends \SplFileInfo
2828
*/
2929
public function __construct($file, $relativePath, $relativePathname)
3030
{
31-
parent::__construct($file);
31+
parent::__construct(realpath($file));
3232
$this->relativePath = $relativePath;
3333
$this->relativePathname = $relativePathname;
3434
}

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,16 @@ public function testFiles()
4848
$this->assertIterator($this->toAbsolute(array('foo/bar.tmp', 'test.php', 'test.py', 'foo bar')), $finder->in(self::$tmpDir)->getIterator());
4949
}
5050

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

0 commit comments

Comments
 (0)