diff --git a/crates/bashkit/src/builtins/rg/mod.rs b/crates/bashkit/src/builtins/rg/mod.rs index 92167543..a1596569 100644 --- a/crates/bashkit/src/builtins/rg/mod.rs +++ b/crates/bashkit/src/builtins/rg/mod.rs @@ -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) } @@ -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(