Skip to content

fix(grep): handle Windows drive-letter paths and CRLF in parseOutput#3321

Merged
code-yeongyu merged 1 commit intocode-yeongyu:devfrom
rlavkvmflzk:fix/grep-windows-crlf-and-drive-letter
Apr 15, 2026
Merged

fix(grep): handle Windows drive-letter paths and CRLF in parseOutput#3321
code-yeongyu merged 1 commit intocode-yeongyu:devfrom
rlavkvmflzk:fix/grep-windows-crlf-and-drive-letter

Conversation

@rlavkvmflzk
Copy link
Copy Markdown
Contributor

@rlavkvmflzk rlavkvmflzk commented Apr 10, 2026

Summary

Fixes grep tool content and count output modes always returning "No matches found" on Windows.

Closes #2962

Root Cause (two issues)

1. Drive-letter regex failure

ripgrep outputs paths like C:\path\file.ts:42:content. The regex ^(.+?):(\d+):(.*)$ matches C as the file group (lazy .+? stops at the first :), then \d+ fails on \path\....

2. CRLF line endings (missed by PR #2976)

ripgrep outputs \r\n on Windows. After split("\n"), each line retains a trailing \r. The $ anchor in the regex does not match before \r, so every line fails.

PR #2976 addressed issue 1 with --path-separator=/, but this flag gets expanded by MSYS2/Git Bash into a full path (C:/Program Files/Git/), causing a separate rg error. It also did not address issue 2.

Fix

  • Update parseOutput and parseCountOutput regexes to handle drive-letter prefixes: ^([A-Za-z]:[\\/].*?|.+?):(\d+):(.*)$
  • Strip trailing \r from each line before matching: line.replace(/\r$/, "")
  • No --path-separator flag (avoids MSYS2 expansion issue)

Why this doesn't break Linux/Mac

  • The \r strip is a no-op when \r is absent
  • The regex uses an alternative ([A-Za-z]:[\\/].*?|.+?) — when no drive letter exists, it falls back to the original .+? behavior

Testing

Verified on Windows 11 + Git Bash + ripgrep 15.1.0 + oh-my-openagent 3.16.0:

Mode Before After
content "No matches found" Correct matches with file, line, text
count Working Working
files_with_matches Working Working

Summary by cubic

Fixes Windows parsing in the grep tool so content and count modes return correct matches instead of "No matches found" by handling drive-letter paths and CRLF line endings.

  • Bug Fixes
    • Strip trailing \r from each output line before matching.
    • Update parseOutput and parseCountOutput regexes to support C:\... paths.
    • Remove --path-separator usage to avoid MSYS2/Git Bash path expansion.

Written for commit b0b19f3. Summary will update on new commits.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 10, 2026

All contributors have signed the CLA. Thank you! ✅
Posted by the CLA Assistant Lite bot.

Copy link
Copy Markdown

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 1 file

Confidence score: 5/5

  • Automated review surfaced no issues in the provided summaries.
  • No files require special attention.

Auto-approved: The fix safely addresses Windows-specific path and line-ending issues using non-breaking regex fallbacks and carriage return stripping, with no impact on Unix systems.

@rlavkvmflzk
Copy link
Copy Markdown
Contributor Author

I have read the CLA Document and I hereby sign the CLA

@rlavkvmflzk
Copy link
Copy Markdown
Contributor Author

recheck

The grep tool's content and count output modes always returned 'No
matches found' on Windows due to two issues:

1. Regex ^(.+?):(\d+):(.*)$ fails on Windows paths like
   C:\path\file.ts:42:content because lazy .+? matches only 'C',
   then \d+ fails on '\path\...'

2. ripgrep outputs CRLF line endings on Windows. After split('\n'),
   trailing \r breaks the $ anchor in the regex, causing every
   line to fail matching.

Fix: update parseOutput and parseCountOutput regexes to handle
drive-letter prefixes ([A-Za-z]:[\/]), and strip trailing \r
from each line before matching.

Note: PR code-yeongyu#2976 attempted to fix (1) with --path-separator=/ but
this flag gets expanded by MSYS2/Git Bash to a full path, causing
a separate rg error. This PR avoids --path-separator entirely.

Closes code-yeongyu#2962
@rlavkvmflzk rlavkvmflzk force-pushed the fix/grep-windows-crlf-and-drive-letter branch from 82ca72a to b0b19f3 Compare April 10, 2026 20:38
github-actions bot added a commit that referenced this pull request Apr 10, 2026
@code-yeongyu code-yeongyu merged commit a47f898 into code-yeongyu:dev Apr 15, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Grep tool content mode always returns 'No matches found' on Windows — drive letter breaks regex parsing

2 participants