Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

[Finder] Glob wildcard while using double-star without ending slash #22239

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions 16 src/Symfony/Component/Finder/Glob.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,19 @@ public static function toRegex($glob, $strictLeadingDot = true, $strictWildcardS

$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 = '[^/]++/';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would that work?
$car = $strictLeadingDot ? '(?:/(?=[^\.])[^/]*+)+' : '(?:/[^/]*+)+'

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nup, it's not. I tried to make it working with a one-liner like that but all my attempts were either not matching "deep children" (level + 1) or matching the folder without its slash (like foo for foo/**)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this $car creation is also more readable.

if (!isset($glob[$i + 3])) {
$car .= '?';
}

if ($strictLeadingDot) {
$car = '(?=[^\.])'.$car;
}

$car = '/(?:'.$car.')*';
$i += 2 + isset($glob[$i + 3]);

if ('/' === $delimiter) {
$car = str_replace('/', '\\/', $car);
}
Expand Down
1 change: 1 addition & 0 deletions 1 src/Symfony/Component/Finder/Tests/Fixtures/one/.dot
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.dot
34 changes: 34 additions & 0 deletions 34 src/Symfony/Component/Finder/Tests/GlobTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,38 @@ public function testGlobToRegexDoubleStarNonStrictDots()

$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);
}
}
Morty Proxy This is a proxified and sanitized view of the page, visit original site.