Skip to content

Commit

Permalink
fix glob parsing and improve error reporting (#3644)
Browse files Browse the repository at this point in the history
Our glob parser was not able to parse alternatives that contain a slash:
`{a/b}`
  • Loading branch information
sokra committed Feb 6, 2023
1 parent 4e5c187 commit 54df174
Showing 1 changed file with 21 additions and 3 deletions.
24 changes: 21 additions & 3 deletions crates/turbo-tasks-fs/src/glob.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::mem::take;

use anyhow::{bail, Result};
use anyhow::{anyhow, bail, Context, Result};
use serde::{Deserialize, Serialize};
use turbo_tasks::trace::TraceRawVcs;

Expand Down Expand Up @@ -75,7 +75,8 @@ impl Glob {
let mut expression = Vec::new();

while !current.is_empty() {
let (part, remainder) = GlobPart::parse(current, false)?;
let (part, remainder) = GlobPart::parse(current, false)
.with_context(|| anyhow!("Failed to parse glob {input}"))?;
expression.push(part);
current = remainder;
}
Expand Down Expand Up @@ -198,7 +199,10 @@ impl GlobPart {
current = &current[1..];
break;
}
_ => bail!("Unterminated glob braces"),
None => bail!("Unterminated glob braces"),
_ => {
// next part of the glob
}
}
}

Expand Down Expand Up @@ -391,6 +395,20 @@ mod tests {
"**/*/next/dist/server/next.js",
"node_modules/next/dist/server/next.js"
)]
#[case::node_modules_root("**/node_modules/**", "node_modules/next/dist/server/next.js")]
#[case::node_modules_nested(
"**/node_modules/**",
"apps/some-app/node_modules/regenerate-unicode-properties/Script_Extensions/Osage.js"
)]
#[case::node_modules_pnpm(
"**/node_modules/**",
"node_modules/.pnpm/regenerate-unicode-properties@9.0.0/node_modules/\
regenerate-unicode-properties/Script_Extensions/Osage.js"
)]
#[case::alternatives_nested1("{a,b/c,d/e/{f,g/h}}", "a")]
#[case::alternatives_nested2("{a,b/c,d/e/{f,g/h}}", "b/c")]
#[case::alternatives_nested3("{a,b/c,d/e/{f,g/h}}", "d/e/f")]
#[case::alternatives_nested4("{a,b/c,d/e/{f,g/h}}", "d/e/g/h")]
fn glob_match(#[case] glob: &str, #[case] path: &str) {
let glob = Glob::parse(glob).unwrap();

Expand Down

0 comments on commit 54df174

Please sign in to comment.