Commit Graph

14 Commits

Author SHA1 Message Date
Sylvestre Ledru be51c04c08 grep: support GREP_COLORS 'mt' and warn on deprecated GREP_COLOR
Two color-handling gaps vs GNU: the 'mt' capability in GREP_COLORS (which
sets both the selected- and context-match colors) was ignored, and the
deprecated GREP_COLOR variable produced no warning. Handle 'mt', and emit
GNU's 'GREP_COLOR=... is deprecated; use GREP_COLORS=mt=...' warning when
color output is actually produced. Fixes the GNU testsuite 'color-colors'
test.
2026-05-30 18:55:55 +02:00
Sylvestre Ledru da32a63663 grep: map invalid back-reference errors to GNU's wording
A back-reference to a non-existent group, e.g. (.)\2, makes oniguruma
fail with 'invalid backref number/name'. GNU words this per engine:
'reference to non-existent subpattern' under -P (PCRE2) and 'Invalid
back reference' for basic/extended (gnulib regex). Translate
ONIGERR_INVALID_BACKREF accordingly (gnu_error_message now takes the
regex mode). Fixes the GNU testsuite 'pcre-wx-backref' test.

Also drop pipe_in() from the compile-error tests added in the previous
commits: those patterns are rejected before stdin is read, so feeding
input raced with the child exiting and intermittently panicked the test
harness with a broken pipe under parallel execution.
2026-05-30 18:02:32 +02:00
Sylvestre Ledru 9c21a7d2f0 grep: handle regex backtracking-limit instead of panicking
A pathological pattern such as -P '((a+)*)+$' makes oniguruma exceed its
match retry limit. The onig crate's search_with_encoding/match_with_encoding
panic on that error, so uu_grep aborted with a Rust panic. Switch to the
fallible *_with_param variants and propagate the error: match_line/is_match
now return io::Result, the failure is mapped to GNU's wording ('exceeded
PCRE's backtracking limit') and surfaces as a normal exit-code-2 diagnostic.
Fixes the GNU testsuite 'pcre-abort' test.
2026-05-30 17:55:31 +02:00
Sylvestre Ledru e767a30c1a grep: emit GNU's 'Invalid range end' for reversed bracket ranges
A reversed range like [b-a] makes oniguruma fail with 'empty range in
char class', which uu_grep wrapped as 'invalid pattern "[b-a]": ...'.
GNU grep instead prints the bare POSIX diagnostic 'Invalid range end'
and exits 2. Translate the oniguruma error code
(ONIGERR_EMPTY_RANGE_IN_CHAR_CLASS) to GNU's wording, leaving other
compile errors to fall back to oniguruma's text. Fixes the GNU testsuite
'reversed-range-endpoints' test.
2026-05-30 17:50:02 +02:00
Sylvestre Ledru 1a3e8a391d grep: reject confusing [:name:] bracket syntax like GNU
GNU grep flags a bracket expression of the form [:name:] (an almost
certain misspelling of [[:name:]]) with a dedicated diagnostic and exit
code 2, whereas oniguruma silently treats it as the character set
{':','n','a','m','e'}. Port GNU's colon_warning_state logic from
parse_bracket_exp (gnulib dfa.c) so basic/extended patterns produce the
same error. Fixes the GNU testsuite 'warn-char-classes' test.
2026-05-30 17:39:29 +02:00
Sylvestre Ledru da0ada8a37 test: use platform-specific expected message for nonexistent-file error 2026-05-30 11:33:47 +02:00
Sylvestre Ledru fcf46d8f56 test: cover -D skip on an explicit special-file argument 2026-05-30 11:28:04 +02:00
Sylvestre Ledru 55cb643545 test: cover strip_dot_prefix for implicit-cwd recursive search 2026-05-30 11:28:04 +02:00
Sylvestre Ledru 89aec4a45a test: cover -T line-number width on the file (not stdin) path 2026-05-30 11:28:03 +02:00
Sylvestre Ledru 6c5b7dc9e3 test: cover -L listing when the pattern matches one file 2026-05-30 11:28:03 +02:00
Sylvestre Ledru ff918e4a63 grep: strip trailing (os error N) from file error messages to match GNU (#6) 2026-05-29 22:24:20 +02:00
Sylvestre Ledru c50c0458cb fix: accept repeated options like GNU grep (#2)
GNU grep tolerates options given more than once (boolean flags are
idempotent, value options take the last occurrence), but clap rejected
them with "cannot be used multiple times" (exit 2). Set
args_override_self(true) so clap replaces rather than errors; args with
ArgAction::Append (-e/-f/--include/--exclude) still accumulate.

Found by the differential fuzzer (e.g. `grep -e .* -E -n -o -n -x`).

Add a regression test covering repeated booleans, repeated value options
(last wins), and that -e still accumulates patterns.
2026-05-29 22:21:27 +02:00
Leonard Hecker ebe62e0cf7 Fix flaky tests 2026-05-28 22:32:49 +02:00
Leonard Hecker 9bff77613e Initial import 2026-05-28 20:19:53 +02:00