Skip to content

Commit

Permalink
bug #26337 [Finder] Fixed leading/trailing / in filename (lyrixx)
Browse files Browse the repository at this point in the history
This PR was merged into the 2.7 branch.

Discussion
----------

[Finder] Fixed leading/trailing / in filename

| Q             | A
| ------------- | ---
| Branch?       | 2.7
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets |
| License       | MIT
| Doc PR        |

---

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'
 )
```

Commits
-------

e17a634 [Finder] Fixed leading/trailing / in filename
  • Loading branch information
fabpot committed Mar 20, 2018
2 parents a1be12e + e17a634 commit 25c2f91
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/Symfony/Component/Finder/SplFileInfo.php
Expand Up @@ -28,7 +28,7 @@ class SplFileInfo extends \SplFileInfo
*/
public function __construct($file, $relativePath, $relativePathname)
{
parent::__construct($file);
parent::__construct(realpath($file) ?: $file);
$this->relativePath = $relativePath;
$this->relativePathname = $relativePathname;
}
Expand Down
18 changes: 16 additions & 2 deletions src/Symfony/Component/Finder/Tests/FinderTest.php
Expand Up @@ -48,6 +48,20 @@ public function testFiles()
$this->assertIterator($this->toAbsolute(array('foo/bar.tmp', 'test.php', 'test.py', 'foo bar')), $finder->in(self::$tmpDir)->getIterator());
}

public function testRemoveTrailingSlash()
{
if ('\\' === \DIRECTORY_SEPARATOR) {
$this->markTestSkipped('This test cannot be run on Windows.');
}

$finder = $this->buildFinder();

$expected = $this->toAbsolute(array('foo/bar.tmp', 'test.php', 'test.py', 'foo bar'));
$in = '//'.realpath(self::$tmpDir).'//';

$this->assertIterator($expected, $finder->in($in)->files()->getIterator());
}

public function testDepth()
{
$finder = $this->buildFinder();
Expand Down Expand Up @@ -504,8 +518,8 @@ public function testMultipleLocationsWithSubDirectories()
$finder->in($locations)->depth('< 10')->name('*.neon');

$expected = array(
__DIR__.'/Fixtures/one'.DIRECTORY_SEPARATOR.'b'.DIRECTORY_SEPARATOR.'c.neon',
__DIR__.'/Fixtures/one'.DIRECTORY_SEPARATOR.'b'.DIRECTORY_SEPARATOR.'d.neon',
__DIR__.DIRECTORY_SEPARATOR.'Fixtures'.DIRECTORY_SEPARATOR.'one'.DIRECTORY_SEPARATOR.'b'.DIRECTORY_SEPARATOR.'c.neon',
__DIR__.DIRECTORY_SEPARATOR.'Fixtures'.DIRECTORY_SEPARATOR.'one'.DIRECTORY_SEPARATOR.'b'.DIRECTORY_SEPARATOR.'d.neon',
);

$this->assertIterator($expected, $finder);
Expand Down
Expand Up @@ -31,7 +31,7 @@ public function testSubPath($baseDir, array $paths, array $subPaths, array $subP

public function getSubPathData()
{
$tmpDir = sys_get_temp_dir().'/symfony_finder';
$tmpDir = sys_get_temp_dir().DIRECTORY_SEPARATOR.'symfony_finder';

return array(
array(
Expand Down

0 comments on commit 25c2f91

Please sign in to comment.