Project
cortex
Description
glob_match() in src/cortex-engine/src/tools/handlers/grep.rs (line 277) is missing the trim_start_matches("**/") normalization that the identical function in glob.rs (line 135) performs. When a user passes a glob_pattern like **/*.rs to the Grep tool, the pattern is matched against the bare filename (e.g., main.rs). Because **/ is not stripped, the pattern **/*.rs requires a literal / to appear in the text being matched. Since the match target is only the filename (no directory separators), the match always fails and every file is skipped, producing zero results.
The glob.rs handler correctly strips **/ before matching:
// glob.rs:135
let pattern = pattern.trim_start_matches("**/");
But grep.rs does not:
// grep.rs:277-294
fn glob_match(pattern: &str, text: &str) -> bool {
let pattern_chars: Vec<char> = pattern.chars().collect();
// No trim_start_matches("**/") here
...
}
Error Message
No error — silently returns zero grep results when glob_pattern contains a **/ prefix.
Debug Logs
No response
System Information
Cortex version: v0.0.7
OS: Linux
Affected file: src/cortex-engine/src/tools/handlers/grep.rs
Affected function: glob_match (line 277)
Steps to Reproduce
- Invoke the Grep tool with
path pointing to a directory containing .rs files and glob_pattern set to **/*.rs.
- The
search_content function at line 200 calls glob_match("**/*.rs", "main.rs").
glob_match tries to match pattern chars ['*', '*', '/', '*', '.', 'r', 's'] against text chars ['m', 'a', 'i', 'n', '.', 'r', 's'].
- The
* wildcards consume characters but eventually the literal / in the pattern must match a character in the text. Since the text is a bare filename with no /, the match fails.
- Every file is skipped → zero results returned.
Expected Behavior
grep_match("**/*.rs", "main.rs") should return true, matching the behavior of glob.rs which strips **/ first, effectively matching *.rs against main.rs.
Actual Behavior
grep_match("**/*.rs", "main.rs") returns false because the **/ prefix is not stripped, and the literal / in the pattern cannot match any character in the bare filename.
Additional Context
This is distinct from #5037 (which reports that glob matching uses filename instead of relative path) and #13055 (which reports glob_pattern being ignored when path is a file). This bug is about the glob_match function itself being inconsistent between grep.rs and glob.rs — the **/ prefix stripping is missing only in grep.rs, causing **/-prefixed patterns to always fail.
The fix is a single line addition in grep.rs glob_match: let pattern = pattern.trim_start_matches("**/"); before converting to chars, matching the glob.rs implementation.
Project
cortex
Description
glob_match()insrc/cortex-engine/src/tools/handlers/grep.rs(line 277) is missing thetrim_start_matches("**/")normalization that the identical function inglob.rs(line 135) performs. When a user passes aglob_patternlike**/*.rsto the Grep tool, the pattern is matched against the bare filename (e.g.,main.rs). Because**/is not stripped, the pattern**/*.rsrequires a literal/to appear in the text being matched. Since the match target is only the filename (no directory separators), the match always fails and every file is skipped, producing zero results.The
glob.rshandler correctly strips**/before matching:But
grep.rsdoes not:Error Message
No error — silently returns zero grep results when
glob_patterncontains a**/prefix.Debug Logs
No response
System Information
Cortex version: v0.0.7
OS: Linux
Affected file:
src/cortex-engine/src/tools/handlers/grep.rsAffected function:
glob_match(line 277)Steps to Reproduce
pathpointing to a directory containing.rsfiles andglob_patternset to**/*.rs.search_contentfunction at line 200 callsglob_match("**/*.rs", "main.rs").glob_matchtries to match pattern chars['*', '*', '/', '*', '.', 'r', 's']against text chars['m', 'a', 'i', 'n', '.', 'r', 's'].*wildcards consume characters but eventually the literal/in the pattern must match a character in the text. Since the text is a bare filename with no/, the match fails.Expected Behavior
grep_match("**/*.rs", "main.rs")should returntrue, matching the behavior ofglob.rswhich strips**/first, effectively matching*.rsagainstmain.rs.Actual Behavior
grep_match("**/*.rs", "main.rs")returnsfalsebecause the**/prefix is not stripped, and the literal/in the pattern cannot match any character in the bare filename.Additional Context
This is distinct from #5037 (which reports that glob matching uses filename instead of relative path) and #13055 (which reports glob_pattern being ignored when path is a file). This bug is about the
glob_matchfunction itself being inconsistent betweengrep.rsandglob.rs— the**/prefix stripping is missing only ingrep.rs, causing**/-prefixed patterns to always fail.The fix is a single line addition in
grep.rsglob_match:let pattern = pattern.trim_start_matches("**/");before converting to chars, matching theglob.rsimplementation.