mirror of
https://github.com/uutils/grep.git
synced 2026-06-10 16:15:11 -07:00
fix: reject multiple patterns when -P/--perl-regexp is used
GNU grep's PCRE backend supports only a single pattern. Supplying
multiple patterns via repeated -e flags, or a pattern string that
contains a literal newline, must exit 2 with the message:
the -P option only supports a single pattern
Add the validation immediately after patterns are collected, before
regex-mode selection. Add a test covering:
- two separate -e flags with -P
- a newline-embedded pattern string with -P
- single -e with -P still works normally
Closes #34
This commit is contained in:
@@ -255,6 +255,14 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
|
||||
));
|
||||
}
|
||||
|
||||
// GNU grep's PCRE backend (-P) supports only a single pattern.
|
||||
if perl_regexp && patterns.len() > 1 {
|
||||
return Err(USimpleError::new(
|
||||
2,
|
||||
"the -P option only supports a single pattern".to_string(),
|
||||
));
|
||||
}
|
||||
|
||||
// Decoded options into enums
|
||||
let regex_mode = if fixed_strings {
|
||||
RegexMode::Fixed
|
||||
|
||||
Reference in New Issue
Block a user