Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 2c3ef42

Browse files
committed
Refactored in order to use only one if and construct the regex
1 parent 94fe26a commit 2c3ef42

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

src/Symfony/Component/Finder/Glob.php

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -60,15 +60,19 @@ public static function toRegex($glob, $strictLeadingDot = true, $strictWildcardS
6060

6161
$firstByte = '/' === $car;
6262

63-
if ($firstByte && $strictWildcardSlash) {
64-
if (isset($glob[$i + 3]) && '**/' === $glob[$i + 1].$glob[$i + 2].$glob[$i + 3]) {
65-
$car = $strictLeadingDot ? '/(?:(?=[^\.])[^/]++/)*' : '/(?:[^/]++/)*';
66-
$i += 3;
67-
} elseif (isset($glob[$i + 2]) && '**' === $glob[$i + 1].$glob[$i + 2]) {
68-
$car = $strictLeadingDot ? '/(?=[^\.]).*' : '/.*';
69-
$i += 2;
63+
if ($firstByte && $strictWildcardSlash && isset($glob[$i + 2]) && '**' === $glob[$i + 1].$glob[$i + 2] && (!isset($glob[$i + 3]) || '/' === $glob[$i + 3])) {
64+
$car = '[^/]++/';
65+
if (!isset($glob[$i + 3])) {
66+
$car .= '?';
7067
}
7168

69+
if ($strictLeadingDot) {
70+
$car = '(?=[^\.])'.$car;
71+
}
72+
73+
$car = '/(?:'.$car.')*';
74+
$i += 2 + isset($glob[$i + 3]);
75+
7276
if ('/' === $delimiter) {
7377
$car = str_replace('/', '\\/', $car);
7478
}

0 commit comments

Comments
 (0)