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

Skip to content

Commit e17a634

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 887cba2 commit e17a634

File tree

3 files changed

+18
-4
lines changed

3 files changed

+18
-4
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) ?: $file);
3232
$this->relativePath = $relativePath;
3333
$this->relativePathname = $relativePathname;
3434
}

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

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,20 @@ 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+
if ('\\' === \DIRECTORY_SEPARATOR) {
54+
$this->markTestSkipped('This test cannot be run on Windows.');
55+
}
56+
57+
$finder = $this->buildFinder();
58+
59+
$expected = $this->toAbsolute(array('foo/bar.tmp', 'test.php', 'test.py', 'foo bar'));
60+
$in = '//'.realpath(self::$tmpDir).'//';
61+
62+
$this->assertIterator($expected, $finder->in($in)->files()->getIterator());
63+
}
64+
5165
public function testDepth()
5266
{
5367
$finder = $this->buildFinder();
@@ -504,8 +518,8 @@ public function testMultipleLocationsWithSubDirectories()
504518
$finder->in($locations)->depth('< 10')->name('*.neon');
505519

506520
$expected = array(
507-
__DIR__.'/Fixtures/one'.DIRECTORY_SEPARATOR.'b'.DIRECTORY_SEPARATOR.'c.neon',
508-
__DIR__.'/Fixtures/one'.DIRECTORY_SEPARATOR.'b'.DIRECTORY_SEPARATOR.'d.neon',
521+
__DIR__.DIRECTORY_SEPARATOR.'Fixtures'.DIRECTORY_SEPARATOR.'one'.DIRECTORY_SEPARATOR.'b'.DIRECTORY_SEPARATOR.'c.neon',
522+
__DIR__.DIRECTORY_SEPARATOR.'Fixtures'.DIRECTORY_SEPARATOR.'one'.DIRECTORY_SEPARATOR.'b'.DIRECTORY_SEPARATOR.'d.neon',
509523
);
510524

511525
$this->assertIterator($expected, $finder);

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public function testSubPath($baseDir, array $paths, array $subPaths, array $subP
3131

3232
public function getSubPathData()
3333
{
34-
$tmpDir = sys_get_temp_dir().'/symfony_finder';
34+
$tmpDir = sys_get_temp_dir().DIRECTORY_SEPARATOR.'symfony_finder';
3535

3636
return array(
3737
array(

0 commit comments

Comments
 (0)