Skip to content

Fix ripgrep output parsing on Windows drive-letter paths - #20

Closed
harshdotcom wants to merge 1 commit into
andrewyng:mainfrom
harshdotcom:fix/windows-ripgrep-parse
Closed

Fix ripgrep output parsing on Windows drive-letter paths#20
harshdotcom wants to merge 1 commit into
andrewyng:mainfrom
harshdotcom:fix/windows-ripgrep-parse

Conversation

@harshdotcom

Copy link
Copy Markdown

What

Fixes the grep tool returning corrupted results on Windows when ripgrep is installed.

_parse_rg split each ripgrep output line with line.split(":", 2). ripgrep is
invoked with an absolute search path, which on Windows starts with a drive
letter (C:\...) — that colon was mistaken for the path:line:text field
separator, so every match reported file "C", line 0, with the real line
number leaked into the text field.

Fix

Anchor the parse on the numeric :<line>: field with a regex
((.+?):(\d+):(.*)), so both the drive-letter colon and any colons inside the
matched text are preserved. A plain rsplit(":", 2) would not work — matched
text frequently contains colons (e.g. def hello():).

Testing

  • Added test_parse_rg_handles_windows_drive_letter_and_colons_in_text
    (platform-independent — hardcodes a Windows-style line). It fails on the old
    split(":", 2) and passes on the fix.
  • Full grep suite passes.

Closes #17

_parse_rg split each line on the first two colons, but ripgrep is invoked
with an absolute path — on Windows that starts with a drive letter (C:\...)
whose colon was mistaken for the path:line:text separator, so every match
reported file "C", line 0, with the line number leaked into the text.

Anchor the parse on the numeric :<line>: field with a regex so the
drive-letter colon and any colons in the matched text are preserved.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@rohitprasad15

Copy link
Copy Markdown
Collaborator

Thanks — you were the first to catch the Windows drive-letter parsing bug, and your fix was correct for the main case. We merged #123, which fixes the emission side instead (--with-filename --null), which also covers colons in filenames and the single-file case where rg omits the filename. Windows grep is now fixed on main, so I'm closing this one. Appreciate the report and fix!

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.

grep tool returns corrupted results on Windows — ripgrep output parser splits on the drive-letter colon

2 participants