fix(grep): handle CRLF line endings in ripgrep output parsing#3292
fix(grep): handle CRLF line endings in ripgrep output parsing#3292zhoufanscut wants to merge 1 commit intocode-yeongyu:devfrom
Conversation
parseOutput and parseCountOutput split on "\n" only, leaving
trailing \r when ripgrep preserves CRLF from source files. This
caused content-mode regex to silently fail, returning zero matches
for any file with Windows line endings.
Change split("\n") to split(/\r?\n/) in both functions so \r is
stripped before regex matching. Also export the two parsers and add
unit tests covering CRLF, LF, and empty-output cases.
|
All contributors have signed the CLA. Thank you! ✅ |
There was a problem hiding this comment.
No issues found across 2 files
Confidence score: 5/5
- Automated review surfaced no issues in the provided summaries.
- No files require special attention.
Auto-approved: Fixes CRLF parsing in ripgrep output using standard regex split. Safe change with comprehensive tests and no impact on existing LF logic.
There was a problem hiding this comment.
Pull request overview
This PR fixes ripgrep output parsing to correctly handle Windows-style CRLF (\r\n) line endings so matches aren’t dropped in content and count modes.
Changes:
- Update
parseOutputandparseCountOutputto split stdout with/\r?\n/instead of"\n". - Export both parser functions to enable direct unit testing.
- Add unit tests covering LF, CRLF, and empty-output cases for both parsers.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
src/tools/grep/cli.ts |
Makes stdout splitting CRLF-tolerant in both parsers; exports parsers for testability. |
src/tools/grep/cli.test.ts |
Adds Bun unit tests validating parsing behavior for LF/CRLF and empty output. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
I have read the CLA Document and I hereby sign the CLA |
Summary
parseOutputandparseCountOutputinsrc/tools/grep/cli.tsto handle CRLF (\r\n) line endings from ripgrep outputProblem
When the Grep tool searches files with Windows-style CRLF line endings, ripgrep preserves the
\rin its stdout. The parsers split on"\n"only, leaving a trailing\ron every line. This causes the content-mode regex/^(.+?):(\d+):(.*)$/to silently fail — the$anchor does not match before\rin JavaScript — so all matches are dropped and the tool returns "No matches found".The
files_with_matchesmode was unaffected because it usesline.trim(), which strips\r. Thecountmode has the same latent bug inparseCountOutput.Reproduction
Fix
Change
output.split("\n")→output.split(/\r?\n/)in bothparseOutput(line 103) andparseCountOutput(line 135). After proper splitting, the existing regexes work correctly with no further changes needed.Changes
src/tools/grep/cli.tssplit("\n")→split(/\r?\n/)inparseOutputandparseCountOutput; export both functions for testabilitysrc/tools/grep/cli.test.ts\r, CRLF count, LF content, LF files-only, and empty outputTesting
result-formatter.test.ts— 5/5 pass (no regressions)cli.test.ts— all assertions verified (import currently blocked by unrelated missingjs-yamldependency in the test runner, logic verified independently)Summary by cubic
Fix parsing of ripgrep output with CRLF line endings so content and count modes return correct results on Windows. Adds tests covering CRLF, LF, and empty-output cases.
/\r?\n/inparseOutputandparseCountOutputinsrc/tools/grep/cli.tsto remove stray\r.src/tools/grep/cli.test.tscovering content, files-only, and count modes for CRLF/LF and empty output.Written for commit 697e44a. Summary will update on new commits.