Enhance context matching for exclude rules with wildcard support

This commit is contained in:
Carlos de Paula 2025-10-20 11:02:29 -03:00
parent 545aad9eea
commit 2b00cae8e1
No known key found for this signature in database

View file

@ -98,12 +98,29 @@ impl Exclude {
return true;
}
// Handle glob patterns
// Handle glob patterns with wildcard
if self.context.ends_with("/**") {
let prefix = &self.context[..self.context.len() - 3];
path.starts_with(prefix)
} else {
path == self.context || path.starts_with(&format!("{}/", self.context))
// Check if path starts with prefix (absolute path match)
if path.starts_with(prefix) {
return true;
}
// Check if path contains the pattern anywhere (for relative patterns like "/target/**")
// This allows "/target/**" to match "/home/user/project/target/debug"
if prefix.starts_with('/') && !prefix.starts_with("//") {
// Single leading slash means relative pattern - check if path contains this segment
let pattern = &prefix[1..]; // Remove leading slash
if path.contains(&format!("/{}/", pattern)) || path.ends_with(&format!("/{}", pattern)) {
return true;
}
}
return false;
}
// Exact match or prefix match for non-wildcard patterns
path == self.context || path.starts_with(&format!("{}/", self.context))
}
}