grep: reject multiple patterns with -P - #50
Closed
wondr-wclabs wants to merge 1 commit into
Closed
Conversation
Merging this PR will not alter performance
Comparing Footnotes
|
Contributor
|
already merged here #40 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #34.
This brings
-Pcloser to GNU grep for the specific PCRE restriction described in the issue: PCRE mode accepts exactly one logical pattern. Other matcher modes still keep the existing multi-pattern behavior.The validation is placed after grep has already normalized all pattern sources into
patternsbecause that is the point where the rule is easiest to express correctly. That means the same check covers:-e, e.g.-P -e a -e b-econtaining a newline, e.g.-P -e 'a\nb'-ffiles with more than one pattern lineI kept this out of Clap argument validation because
-e,-f, and positional patterns all flow through different input paths and only become equivalent after the existing pattern-splitting logic. Checking the normalized pattern count avoids duplicating that logic and keeps the restriction specific toRegexMode::Perl.Validation:
printf 'abc\n' | cargo run --quiet -- -P -e a -e bnow exits2withgrep: the -P option only supports a single patterncargo test pcre_rejects_multiple_patterns -- --nocapturecargo testcargo test --no-fail-fastcargo fmt --all -- --checkcargo clippy --all-targets --workspace -p uu_grep -- -D warningsgit diff --check