From abe7d4210e0fe5c0b9322ec5210c6a6aadaa3db5 Mon Sep 17 00:00:00 2001 From: vegetablechicken233 <25945262+vegetablechicken233@users.noreply.github.com> Date: Mon, 15 Jun 2026 17:30:50 +0800 Subject: [PATCH] fix(grep): use portable --null in system grep fallback (BSD/macOS) The system-grep fallback (used when ripgrep is not installed) passed -rnHZ, relying on -Z for the NUL filename separator the match parser requires. -Z only means --null on GNU grep; on BSD/macOS grep it is an alias for --decompress (zgrep mode), so output is plain file:line:content with no NUL. parse_match_line() then matches zero filenames and every result collapses into "N matches in 0 files" with all lines hidden behind [+N more]. Use the long option --null instead, which both GNU and BSD grep define as "print a zero-byte after the file name". Related to #2310 Co-Authored-By: Claude Fable 5 --- src/cmds/system/grep_cmd.rs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/cmds/system/grep_cmd.rs b/src/cmds/system/grep_cmd.rs index a7d715056..072ebc28d 100644 --- a/src/cmds/system/grep_cmd.rs +++ b/src/cmds/system/grep_cmd.rs @@ -349,7 +349,9 @@ pub fn run( for p in &patterns { grep_cmd.args(["-e", p]); } - grep_cmd.args(["-rnHZ", "--"]); + // --null (not -Z): on BSD/macOS grep -Z means --decompress, not the + // NUL filename separator parse_match_line() needs (issue #2310). + grep_cmd.args(["-rnH", "--null", "--"]); grep_cmd.args(&paths); exec_capture(&mut grep_cmd) }) @@ -465,8 +467,9 @@ pub fn run( /// Parses a single rg/grep match line of the form `file\0line_number:content`. /// -/// Requires the underlying command to be invoked with `-0` (rg) or `-Z` (grep) -/// so the filename is NUL-separated from `line:content`. NUL cannot appear in +/// Requires the underlying command to be invoked with `-0` (rg) or `--null` +/// (grep) so the filename is NUL-separated from `line:content`. NUL cannot +/// appear in /// file paths, so the parser is unambiguous regardless of: /// - content with `:` or `::` (e.g. `ClassRegistry::init(...)`, issue #1436); /// - paths with embedded `:` (Windows drive letters, weird filenames like