Skip to content

[BUG] [v0.0.7] GrepHandler glob_match() does not strip **/ prefix — glob patterns like **/*.rs silently match zero files (grep.rs:277) #18537

Description

@echoforge2200

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

  1. Invoke the Grep tool with path pointing to a directory containing .rs files and glob_pattern set to **/*.rs.
  2. The search_content function at line 200 calls glob_match("**/*.rs", "main.rs").
  3. glob_match tries to match pattern chars ['*', '*', '/', '*', '.', 'r', 's'] against text chars ['m', 'a', 'i', 'n', '.', 'r', 's'].
  4. 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.
  5. 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions