框架升级及修复升级后的bug
This commit is contained in:
+12
-4
@@ -37,15 +37,16 @@ class Glob
|
||||
{
|
||||
/**
|
||||
* Returns a regexp which is the equivalent of the glob pattern.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function toRegex(string $glob, bool $strictLeadingDot = true, bool $strictWildcardSlash = true, string $delimiter = '#')
|
||||
public static function toRegex(string $glob, bool $strictLeadingDot = true, bool $strictWildcardSlash = true, string $delimiter = '#'): string
|
||||
{
|
||||
$firstByte = true;
|
||||
$escaping = false;
|
||||
$inCurlies = 0;
|
||||
$regex = '';
|
||||
if ($unanchored = str_starts_with($glob, '**/')) {
|
||||
$glob = '/'.$glob;
|
||||
}
|
||||
$sizeGlob = \strlen($glob);
|
||||
for ($i = 0; $i < $sizeGlob; ++$i) {
|
||||
$car = $glob[$i];
|
||||
@@ -76,7 +77,10 @@ class Glob
|
||||
if ($delimiter === $car || '.' === $car || '(' === $car || ')' === $car || '|' === $car || '+' === $car || '^' === $car || '$' === $car) {
|
||||
$regex .= "\\$car";
|
||||
} elseif ('*' === $car) {
|
||||
$regex .= $escaping ? '\\*' : ($strictWildcardSlash ? '[^/]*' : '.*');
|
||||
if ($escaping || $strictWildcardSlash || !str_ends_with($regex, '.*')) {
|
||||
// ".*.*" matches the same as ".*" but backtracks quadratically
|
||||
$regex .= $escaping ? '\\*' : ($strictWildcardSlash ? '[^/]*' : '.*');
|
||||
}
|
||||
} elseif ('?' === $car) {
|
||||
$regex .= $escaping ? '\\?' : ($strictWildcardSlash ? '[^/]' : '.');
|
||||
} elseif ('{' === $car) {
|
||||
@@ -106,6 +110,10 @@ class Glob
|
||||
$escaping = false;
|
||||
}
|
||||
|
||||
if ($unanchored) {
|
||||
$regex = substr_replace($regex, '?', 1 + ('/' === $delimiter) + ($strictLeadingDot ? \strlen('(?=[^\.])') : 0), 0);
|
||||
}
|
||||
|
||||
return $delimiter.'^'.$regex.'$'.$delimiter;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user