Skip to content
Open
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
24 changes: 24 additions & 0 deletions crates/bashkit/src/builtins/rg/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1130,6 +1130,13 @@ impl RgOptions {
}

opts.paths = positional;

if opts.only_matching && opts.patterns.iter().any(|pattern| pattern.is_empty()) {
return Err(Error::Execution(
"rg: empty pattern is not allowed with --only-matching".to_string(),
));
}

Ok(opts)
}

Expand Down Expand Up @@ -9985,6 +9992,23 @@ mod tests {
assert!(!result.stdout.contains("vendor"));
}

#[test]
fn test_rg_only_matching_rejects_empty_pattern() {
let args = vec![
"-o".to_string(),
"-e".to_string(),
"".to_string(),
"/test.txt".to_string(),
];
match RgOptions::parse(&args) {
Err(Error::Execution(msg)) => {
assert_eq!(msg, "rg: empty pattern is not allowed with --only-matching")
}
Err(other) => panic!("unexpected error: {other}"),
Ok(_) => panic!("expected parse error"),
}
}

#[tokio::test]
async fn test_rg_only_matching_and_quiet() {
let only = run_rg(
Expand Down
Loading