From 8c0d3d455905cd9881e616a22a1820e5fe26c71a Mon Sep 17 00:00:00 2001 From: Victorien Elvinger Date: Sat, 27 Apr 2024 13:11:01 +0200 Subject: [PATCH] fix(glob): correctly handle relative patterns --- CHANGELOG.md | 11 +++++++++++ crates/biome_service/src/matcher/pattern.rs | 8 +++----- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8d0c5dc87503..ce2f07b30ed6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -52,6 +52,17 @@ our [guidelines for writing a good changelog entry](https://github.com/biomejs/b Contributed by @Conaclos +- Relative glob patterns are now correctly handled ([#2421](https://github.com/biomejs/biome/issues/2421)). + + Biome relies on an internal fork of the [glob crate](https://crates.io/crates/glob). + This crate converts relative glob patterns into recursive glob patterns. + This means that `./file' is equivalent to `./**/file'. + + This is surprising behavior and has been reported as a bug by our users. + Biome no longer converts relative glob patterns to recursive glob patterns. + + Contributed by @Conaclos + ### Configuration ### Editors diff --git a/crates/biome_service/src/matcher/pattern.rs b/crates/biome_service/src/matcher/pattern.rs index 291056460fb5..c80d2e390229 100644 --- a/crates/biome_service/src/matcher/pattern.rs +++ b/crates/biome_service/src/matcher/pattern.rs @@ -126,10 +126,8 @@ impl Pattern { // eg. "./test" or ".\test" let is_relative = matches!(chars.get(..2), Some(['.', sep]) if path::is_separator(*sep)); if is_relative { - // If a pattern starts with a relative prefix, strip it from the - // pattern and replace it with a "**" sequence + // If a pattern starts with a relative prefix, strip it from the pattern i += 2; - tokens.push(AnyRecursiveSequence); } else { // A pattern is absolute if it starts with a path separator, eg. "/home" or "\\?\C:\Users" let mut is_absolute = chars.first().map_or(false, |c| path::is_separator(*c)); @@ -862,11 +860,11 @@ mod test { #[test] fn test_pattern_relative() { - assert!(Pattern::new("./b").unwrap().matches_path(Path::new("a/b"))); + assert!(!Pattern::new("./b").unwrap().matches_path(Path::new("a/b"))); assert!(Pattern::new("b").unwrap().matches_path(Path::new("a/b"))); if cfg!(windows) { - assert!(Pattern::new(".\\b") + assert!(!Pattern::new(".\\b") .unwrap() .matches_path(Path::new("a\\b"))); assert!(Pattern::new("b").unwrap().matches_path(Path::new("a\\b")));