Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 34 additions & 4 deletions crates/bashkit/src/builtins/rg/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
Expand Down Expand Up @@ -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();
Expand Down
Loading