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
28 changes: 26 additions & 2 deletions crates/bashkit/src/builtins/rg/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3544,6 +3544,7 @@ async fn try_indexed_search(
opts: &RgOptions,
cwd: &Path,
) -> Option<Vec<RgInput>> {
let index_can_use_literal = opts.fixed_strings && !opts.word_boundary && !opts.line_regexp;
if opts.invert_match
|| opts.files_without_matches
|| opts.crlf
Expand All @@ -3555,7 +3556,7 @@ async fn try_indexed_search(
|| opts.follow_symlinks
|| opts.search_zip
|| opts.preprocessor.is_some()
|| (!opts.unicode && !opts.fixed_strings)
|| (!opts.unicode && !index_can_use_literal)
|| opts.sort != RgSort::Path
{
return None;
Expand Down Expand Up @@ -3587,7 +3588,6 @@ async fn try_indexed_search(
if !caps.content_search || (!opts.fixed_strings && !caps.regex) {
return None;
}
let index_can_use_literal = opts.fixed_strings && !opts.word_boundary && !opts.line_regexp;
let pattern = if index_can_use_literal {
opts.patterns[0].clone()
} else {
Expand Down Expand Up @@ -12876,6 +12876,30 @@ mod tests {
assert_eq!(result.stdout, "needle\r\n");
}

#[tokio::test]
async fn test_rg_indexed_search_skipped_for_no_unicode_non_literal_queries() {
let inner = InMemoryFs::new();
inner.mkdir(Path::new("/safe"), true).await.unwrap();
inner
.write_file(Path::new("/safe/unicode.txt"), b"cafe\ncafe\ncaf\xc3\xa9\n")
.await
.unwrap();

let fs = Arc::new(IndexedTestFs {
inner,
matches: vec![],
});

let result = run_rg_with_fs(
&["--no-ignore", "--no-unicode", "-F", "-w", "caf", "/safe"],
None,
fs,
)
.await;
assert_eq!(result.exit_code, 0);
assert_eq!(result.stdout, "/safe/unicode.txt:café\n");
}

#[test]
fn real_rg_binary_is_available_for_differential_tests() {
require_real_rg();
Expand Down
Loading