MCPcopy Create free account
hub / github.com/AI45Lab/Code / glob_match

Method glob_match

core/src/permissions/rule.rs:184–201  ·  view source on GitHub ↗

Perform glob-style pattern matching Supports: - `*` matches any sequence of characters (except /) - `**` matches any sequence including / - `:*` at the end matches any suffix (including empty)

(&self, pattern: &str, text: &str)

Source from the content-addressed store, hash-verified

182 /// - `**` matches any sequence including /
183 /// - `:*` at the end matches any suffix (including empty)
184 fn glob_match(&self, pattern: &str, text: &str) -> bool {
185 // Handle special `:*` suffix (matches any args after the prefix)
186 if let Some(prefix) = pattern.strip_suffix(":*") {
187 return text.starts_with(prefix);
188 }
189
190 // Normalize Windows backslashes to forward slashes for consistent matching
191 let text = text.replace('\\', "/");
192
193 // Convert glob pattern to regex pattern
194 let regex_pattern = Self::glob_to_regex(pattern);
195 if let Ok(re) = regex::Regex::new(&regex_pattern) {
196 re.is_match(&text)
197 } else {
198 // Fallback to simple prefix match if regex fails
199 text.starts_with(pattern)
200 }
201 }
202
203 /// Convert glob pattern to regex pattern
204 fn glob_to_regex(pattern: &str) -> String {

Callers 2

matches_tool_nameMethod · 0.45
matches_argsMethod · 0.45

Calls

no outgoing calls

Tested by

no test coverage detected