Skip to content

Commit 40c2cbd

Browse files
committed
bug #19951 [Finder] Trim trailing directory slash in ExcludeDirectoryFilterIterator (ro0NL)
This PR was merged into the 2.7 branch. Discussion ---------- [Finder] Trim trailing directory slash in ExcludeDirectoryFilterIterator | Q | A | ------------- | --- | Branch? | 2.7 | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #19599 | License | MIT | Doc PR | reference to the documentation PR, if any In this context `path` equals `path/` Commits ------- e0e5f0c apply rtrim
2 parents e4f498a + e0e5f0c commit 40c2cbd

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ public function __construct(\Iterator $iterator, array $directories)
3535
$this->isRecursive = $iterator instanceof \RecursiveIterator;
3636
$patterns = array();
3737
foreach ($directories as $directory) {
38+
$directory = rtrim($directory, '/');
3839
if (!$this->isRecursive || false !== strpos($directory, '/')) {
3940
$patterns[] = preg_quote($directory, '#');
4041
} else {
@@ -51,7 +52,7 @@ public function __construct(\Iterator $iterator, array $directories)
5152
/**
5253
* Filters the iterator values.
5354
*
54-
* @return bool true if the value should be kept, false otherwise
55+
* @return bool True if the value should be kept, false otherwise
5556
*/
5657
public function accept()
5758
{

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,23 @@ public function getAcceptData()
5858
'foo bar',
5959
);
6060

61+
$toto = array(
62+
'.bar',
63+
'.foo',
64+
'.foo/.bar',
65+
'.foo/bar',
66+
'.git',
67+
'test.py',
68+
'foo',
69+
'foo/bar.tmp',
70+
'test.php',
71+
'foo bar',
72+
);
73+
6174
return array(
6275
array(array('foo'), $this->toAbsolute($foo)),
6376
array(array('fo'), $this->toAbsolute($fo)),
77+
array(array('toto/'), $this->toAbsolute($toto)),
6478
);
6579
}
6680
}

0 commit comments

Comments
 (0)