Skip to content

Commit cad7f52

Browse files
committed
Ssquare
1 parent 02c96c3 commit cad7f52

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

src/Util/FileMatcher.php

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@ public static function match(string $path, FileMatcherPattern $pattern): bool
3939

4040
$regex = self::toRegEx($pattern->path);
4141

42-
return preg_match($regex, $path) !== 0;
42+
$result = preg_match($regex, $path) !== 0;
43+
return $result;
4344
}
4445

4546
/**
@@ -181,14 +182,22 @@ private static function processTokens(array $tokens): array
181182
continue;
182183
}
183184

185+
// if this was _not_ a bang preceded by a `[` token then convert it
186+
// to a literal char
184187
if ($type === self::T_BANG) {
185188
$resolved[] = [self::T_CHAR, $char];
186189
continue;
187190
}
188191

192+
if ($type === self::T_BRACKET_OPEN && $tokens[$offset + 1][0] === self::T_BRACKET_CLOSE) {
193+
$resolved[] = [self::T_BRACKET_OPEN, $char];
194+
$brackets[] = array_key_last($resolved);
195+
$resolved[] = [self::T_CHAR, $char];
196+
continue;
197+
}
189198
if ($type === self::T_BRACKET_OPEN) {
190-
$brackets[] = $offset;
191199
$resolved[] = [$type, $char];
200+
$brackets[] = array_key_last($resolved);
192201
continue;
193202
}
194203

tests/unit/Util/FileMatcherTest.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -371,7 +371,6 @@ public static function provideCharacterGroup(): Generator
371371
'/a' => false,
372372
'/' => false,
373373
],
374-
'Unterminated square bracket 2',
375374
];
376375

377376
yield 'match ranges' => [

0 commit comments

Comments
 (0)