From d3d2a022c858943f0edc055c289fbfa694b28dc7 Mon Sep 17 00:00:00 2001 From: Mykhailo Chalyi Date: Fri, 5 Jun 2026 14:49:52 -0500 Subject: [PATCH] fix(rg): preserve indexed explicit binary inputs --- crates/bashkit/src/builtins/rg/mod.rs | 38 ++++++++++++++++++++++++--- 1 file changed, 34 insertions(+), 4 deletions(-) diff --git a/crates/bashkit/src/builtins/rg/mod.rs b/crates/bashkit/src/builtins/rg/mod.rs index 69a55ea53..b57e7d961 100644 --- a/crates/bashkit/src/builtins/rg/mod.rs +++ b/crates/bashkit/src/builtins/rg/mod.rs @@ -3876,10 +3876,14 @@ async fn try_indexed_search( continue; } if let Ok(content) = fs.read_file(&candidate).await { - inputs.push(RgInput::discovered( - display_path_for(&candidate, cwd, root_arg.as_deref(), opts), - decode_rg_content(&content, opts), - )); + let display = display_path_for(&candidate, cwd, root_arg.as_deref(), opts); + let content = decode_rg_content(&content, opts); + let input = if explicit_file_match { + RgInput::explicit(display, content) + } else { + RgInput::discovered(display, content) + }; + inputs.push(input); } } } @@ -13871,6 +13875,32 @@ mod tests { assert_eq!(result.stdout, ""); } + #[tokio::test] + async fn test_rg_indexed_explicit_binary_file_reports_match_by_default() { + let inner = InMemoryFs::new(); + inner.mkdir(Path::new("/proj"), true).await.unwrap(); + inner + .write_file(Path::new("/proj/bin.dat"), b"abc\0needle\n") + .await + .unwrap(); + + let fs = Arc::new(IndexedTestFs { + inner, + matches: vec![SearchMatch { + path: PathBuf::from("/proj/bin.dat"), + line_number: 1, + line_content: "abc\0needle".to_string(), + }], + }); + + let result = run_rg_with_fs(&["needle", "/proj/bin.dat"], None, fs).await; + assert_eq!(result.exit_code, 0); + assert_eq!( + result.stdout, + "binary file matches (found \"\\0\" byte around offset 3)\n" + ); + } + #[tokio::test] async fn test_rg_crlf_skips_indexed_prefilter_and_falls_back_to_linear_scan() { let inner = InMemoryFs::new();