Skip to content

Commit db561cb

Browse files
authored
Turbopack: fix glob with empty alternative branch (vercel#82275)
This came up during NFT where the ignore pattern `'**/node_modules/react{,-dom,-dom-server-turbopack}/**/*.development.js'` wasn't applied.
1 parent b085faf commit db561cb

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

turbopack/crates/turbo-tasks-fs/src/glob.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,8 @@ mod tests {
193193
#[case::alternatives_nested2("{a,b/c,d/e/{f,g/h}}", "b/c")]
194194
#[case::alternatives_nested3("{a,b/c,d/e/{f,g/h}}", "d/e/f")]
195195
#[case::alternatives_nested4("{a,b/c,d/e/{f,g/h}}", "d/e/g/h")]
196+
#[case::alternatives_empty1("react{,-dom}", "react")]
197+
#[case::alternatives_empty2("react{,-dom}", "react-dom")]
196198
#[case::alternatives_chars("[abc]", "b")]
197199
fn glob_match(#[case] glob: &str, #[case] path: &str) {
198200
let glob = Glob::parse(glob).unwrap();

turbopack/crates/turbo-tasks-fs/src/globset.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,10 +253,13 @@ impl Tokens {
253253

254254
fn build_alternates(re: &mut String, patterns: &Vec<Tokens>, branch_fn: fn(&[Token], &mut String)) {
255255
let mut parts = Vec::with_capacity(patterns.len());
256+
let mut has_empty_part = false;
256257
for pat in patterns {
257258
let mut altre = String::new();
258259
branch_fn(pat, &mut altre);
259-
if !altre.is_empty() {
260+
if altre.is_empty() {
261+
has_empty_part = true;
262+
} else {
260263
parts.push(altre);
261264
}
262265
}
@@ -265,6 +268,9 @@ fn build_alternates(re: &mut String, patterns: &Vec<Tokens>, branch_fn: fn(&[Tok
265268
// resulting alternation '()' would be an error.
266269
if !parts.is_empty() {
267270
re.push_str("(?:");
271+
if has_empty_part {
272+
re.push('|');
273+
}
268274
re.push_str(&parts.join("|"));
269275
re.push(')');
270276
}

0 commit comments

Comments
 (0)