Skip to content

Commit 9895421

Browse files
kamazeesebastianbergmann
authored andcommitted
Ignore all if exclude contains parent directory
1 parent 50c7854 commit 9895421

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

src/Iterator.php

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,11 @@ class File_Iterator extends FilterIterator
3939
*/
4040
protected $basepath;
4141

42+
/**
43+
* @var bool
44+
*/
45+
private $excludeAll = FALSE;
46+
4247
/**
4348
* @param Iterator $iterator
4449
* @param array $suffixes
@@ -58,6 +63,11 @@ public function __construct(Iterator $iterator, array $suffixes = array(), array
5863
$basepath = NULL;
5964
} else {
6065
foreach ($exclude as &$_exclude) {
66+
if (self::isExcludeParentOrSame($_exclude, $basepath)) {
67+
$this->excludeAll = TRUE;
68+
continue;
69+
}
70+
6171
$_exclude = str_replace($basepath, '', $_exclude);
6272
}
6373
}
@@ -100,6 +110,10 @@ public function accept()
100110
*/
101111
protected function acceptPath($path)
102112
{
113+
if ($this->excludeAll) {
114+
return FALSE;
115+
}
116+
103117
foreach ($this->exclude as $exclude) {
104118
if (strpos($path, $exclude) === 0) {
105119
return FALSE;
@@ -155,4 +169,19 @@ protected function acceptSubString($filename, array $subStrings, $type)
155169

156170
return $matched;
157171
}
172+
173+
private static function isExcludeParentOrSame($exclude, $basepath)
174+
{
175+
if ($exclude === $basepath) {
176+
return TRUE;
177+
}
178+
179+
$excludeWithSeparator = $exclude . DIRECTORY_SEPARATOR;
180+
$prefixLength = strlen($excludeWithSeparator);
181+
if ($excludeWithSeparator === substr($basepath, 0, $prefixLength)) {
182+
return TRUE;
183+
}
184+
185+
return FALSE;
186+
}
158187
}

0 commit comments

Comments
 (0)