fix(Glob): avoid exiting skip_brace early (#17582)

This commit is contained in:
dalaoshu
2025-02-23 15:14:08 +08:00
committed by GitHub
parent 0bb0bf7c08
commit 5167ed20f9
2 changed files with 8 additions and 2 deletions

View File

@@ -384,6 +384,7 @@ fn matchBraceBranch(state: *State, glob: []const u8, path: []const u8, open_brac
fn skipBranch(state: *State, glob: []const u8) void {
var in_brackets = false;
const end_brace_depth = state.brace_depth - 1;
while (state.glob_index < glob.len) {
switch (glob[state.glob_index]) {
'{' => if (!in_brackets) {
@@ -391,8 +392,10 @@ fn skipBranch(state: *State, glob: []const u8) void {
},
'}' => if (!in_brackets) {
state.brace_depth -= 1;
state.glob_index += 1;
return;
if (state.brace_depth == end_brace_depth) {
state.glob_index += 1;
return;
}
},
'[' => if (!in_brackets) {
in_brackets = true;

View File

@@ -117,6 +117,9 @@ describe("Glob.match", () => {
glob = new Glob("{a,b}/c/{d,e}/**/*est.ts");
expect(glob.match("a/c/d/one/two/three.test.ts"));
glob = new Glob("{a,{d,e}b}/c");
expect(glob.match("a/c")).toBeTrue();
glob = new Glob("{**/a,**/b}");
expect(glob.match("b")).toBeTrue();