[Finder] Glob wildcard while using double-star without ending slash
This commit is contained in:
parent
e3d99649aa
commit
170b0ace2c
@ -60,9 +60,19 @@ class Glob
|
||||
|
||||
$firstByte = '/' === $car;
|
||||
|
||||
if ($firstByte && $strictWildcardSlash && isset($glob[$i + 3]) && '**/' === $glob[$i + 1].$glob[$i + 2].$glob[$i + 3]) {
|
||||
$car = $strictLeadingDot ? '/(?:(?=[^\.])[^/]++/)*' : '/(?:[^/]++/)*';
|
||||
$i += 3;
|
||||
if ($firstByte && $strictWildcardSlash && isset($glob[$i + 2]) && '**' === $glob[$i + 1].$glob[$i + 2] && (!isset($glob[$i + 3]) || '/' === $glob[$i + 3])) {
|
||||
$car = '[^/]++/';
|
||||
if (!isset($glob[$i + 3])) {
|
||||
$car .= '?';
|
||||
}
|
||||
|
||||
if ($strictLeadingDot) {
|
||||
$car = '(?=[^\.])'.$car;
|
||||
}
|
||||
|
||||
$car = '/(?:'.$car.')*';
|
||||
$i += 2 + isset($glob[$i + 3]);
|
||||
|
||||
if ('/' === $delimiter) {
|
||||
$car = str_replace('/', '\\/', $car);
|
||||
}
|
||||
|
1
src/Symfony/Component/Finder/Tests/Fixtures/one/.dot
Normal file
1
src/Symfony/Component/Finder/Tests/Fixtures/one/.dot
Normal file
@ -0,0 +1 @@
|
||||
.dot
|
@ -58,4 +58,38 @@ class GlobTest extends TestCase
|
||||
|
||||
$this->assertSame(array('.dot/b/c.neon', '.dot/b/d.neon', 'one/b/c.neon', 'one/b/d.neon'), $match);
|
||||
}
|
||||
|
||||
public function testGlobToRegexDoubleStarWithoutLeadingSlash()
|
||||
{
|
||||
$finder = new Finder();
|
||||
$finder->ignoreDotFiles(false);
|
||||
$regex = Glob::toRegex('/Fixtures/one/**');
|
||||
|
||||
foreach ($finder->in(__DIR__) as $k => $v) {
|
||||
$k = str_replace(DIRECTORY_SEPARATOR, '/', $k);
|
||||
if (preg_match($regex, substr($k, strlen(__DIR__)))) {
|
||||
$match[] = substr($k, 10 + strlen(__DIR__));
|
||||
}
|
||||
}
|
||||
sort($match);
|
||||
|
||||
$this->assertSame(array('one/a', 'one/b', 'one/b/c.neon', 'one/b/d.neon'), $match);
|
||||
}
|
||||
|
||||
public function testGlobToRegexDoubleStarWithoutLeadingSlashNotStrictLeadingDot()
|
||||
{
|
||||
$finder = new Finder();
|
||||
$finder->ignoreDotFiles(false);
|
||||
$regex = Glob::toRegex('/Fixtures/one/**', false);
|
||||
|
||||
foreach ($finder->in(__DIR__) as $k => $v) {
|
||||
$k = str_replace(DIRECTORY_SEPARATOR, '/', $k);
|
||||
if (preg_match($regex, substr($k, strlen(__DIR__)))) {
|
||||
$match[] = substr($k, 10 + strlen(__DIR__));
|
||||
}
|
||||
}
|
||||
sort($match);
|
||||
|
||||
$this->assertSame(array('one/.dot', 'one/a', 'one/b', 'one/b/c.neon', 'one/b/d.neon'), $match);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user