Skip to content

Commit 0803322

Browse files
committed
Update
1 parent 9b308c3 commit 0803322

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

src/Util/FileMatcher.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,8 @@ public static function toRegEx($glob, $flags = 0): string
6161
$regex .= '-';
6262
break;
6363
case '!':
64-
// complementation/negation
65-
if ($glob[$i - 1] === '[') {
64+
// complementation/negation: taking into account escaped square brackets
65+
if ($glob[$i - 1] === '[' && ($glob[$i - 2] !== '\\' || ($glob[$i -2] === '\\' && $glob[$i - 3] === '\\'))) {
6666
$regex .= '^';
6767
break;
6868
}
@@ -131,6 +131,7 @@ public static function toRegEx($glob, $flags = 0): string
131131

132132
$regex .= '(/|$)';
133133

134+
dump($regex);
134135
return '{^'.$regex.'}';
135136
}
136137

tests/unit/Util/FileMatcherTest.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -493,7 +493,12 @@ public static function provideCharacterGroup(): Generator
493493
'/a/[!a-c]/c/d' => true,
494494
'/b/[!a-c]/c/d' => false,
495495
],
496-
'Regex escaping',
496+
];
497+
yield 'literal backslash neagted group' => [
498+
new FileMatcherPattern('/a/\\\[!a-c]/c'),
499+
[
500+
'/a/\\d/c' => true,
501+
],
497502
];
498503

499504
// TODO: test all the character clases

0 commit comments

Comments
 (0)