grep - regex syntax errors print Oniguruma's wording instead of GNU's messages
I maintainer di solito rispondono entro 2 giorni
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 2/5
- Tempo stimato
- 1-3 ore
- Idoneità per principianti
- 75/100
Direzione di ricerca
Inizia in src/matcher.rs, da CompiledPattern::compile e dal suo ripiego compile_with, poi esamina la traduzione esistente degli errori regex e i test nelle vicinanze. Aggiungi test per i casi di formulazione GNU elencati nell’issue ed esegui i test grep che verificano questi argomenti. Il lavoro è completato quando gli errori di sintassi elencati producono stderr compatibile con GNU, mantenendo il codice di uscita 2 e stdout vuoto.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Known: #151 (open PR) — https://github.com/uutils/grep/pull/151; #71 (merged PR) — https://github.com/uutils/grep/pull/71
When a basic or extended pattern has a syntax error, both tools print nothing on stdout and
exit 2, but the message differs. GNU grep uses a small fixed set of messages
(Unmatched [, [^, [:, [., or [=, Unmatched ( or \(, Trailing backslash, ...).
uu_grep prints invalid pattern "<pattern>": <Oniguruma message>. Exit codes and match
results are fine; only stderr differs, which breaks scripts and test suites that compare it.
Reproduction
Rust (incorrect)
$ printf 'a\n' | ./target/release/grep '[a'
grep: invalid pattern "[a": premature end of char-class
# Exit code: 2
$ printf 'a\n' | ./target/release/grep '\(a'
grep: invalid pattern "\(a": end pattern with unmatched parenthesis
# Exit code: 2
$ printf 'a\n' | ./target/release/grep 'a\'
grep: invalid pattern "a\": end pattern at escape
# Exit code: 2
GNU (correct)
$ printf 'a\n' | LC_ALL=C /usr/bin/grep '[a'
grep: Unmatched [, [^, [:, [., or [=
# Exit code: 2
$ printf 'a\n' | LC_ALL=C /usr/bin/grep '\(a'
grep: Unmatched ( or \(
# Exit code: 2
$ printf 'a\n' | LC_ALL=C /usr/bin/grep 'a\'
grep: Trailing backslash
# Exit code: 2
Observed mapping (Oniguruma code -> GNU 3.12 message, LC_ALL=C):
| Oniguruma error | example | GNU message |
|---|---|---|
ONIGERR_PREMATURE_END_OF_CHAR_CLASS |
[a, [[:alpha:] |
Unmatched [, [^, [:, [., or [= (a lone trailing [ as in a[ gives Invalid regular expression) |
ONIGERR_END_PATTERN_WITH_UNMATCHED_PARENTHESIS |
\(a, -E '(a' |
Unmatched ( or \( |
ONIGERR_UNMATCHED_CLOSE_PARENTHESIS |
a\) |
Unmatched ) or \) |
ONIGERR_END_PATTERN_AT_ESCAPE |
a\, -E 'a\' |
Trailing backslash |
ONIGERR_INVALID_REPEAT_RANGE_PATTERN |
a\{1 / a\{x\} |
Unmatched \{ / Invalid content of \{\} |
ONIGERR_INVALID_BACKREF |
\(a\)\2, -E '(a)\2' |
Invalid back reference |
Root cause
src/matcher.rs:333, the fallback arm in compile_with inside CompiledPattern::compile:
let message = match err.code {
ONIGERR_EMPTY_RANGE_IN_CHAR_CLASS => "Invalid range end".to_string(),
_ => format!("invalid pattern \"{pattern}\": {}", err.message),
};
Only the reversed-range code is translated (added in #71); everything else falls through to
Oniguruma's text.
Test
#[test]
fn regex_syntax_errors_use_gnu_messages() {
let cases: [(&[&str], &str); 5] = [
(&["[x"], "Unmatched [, [^, [:, [., or [="),
(&["\\(x"], "Unmatched ( or \\("),
(&["-E", "(x"], "Unmatched ( or \\("),
(&["x\\)"], "Unmatched ) or \\)"),
(&["x\\"], "Trailing backslash"),
];
for (args, message) in cases {
let (_s, mut c) = ucmd();
c.args(args)
.pipe_in("x\n")
.fails_with_code(2)
.no_stdout()
.stderr_is(format!("grep: {message}\n"));
}
}
Reported by Anthropic's OSS Scanner (ANT-2026-PS745G19).
- Lingua principale
- Rust
- Stelle
- 147
- Fork
- 34
- Merge medio
- 3g 18h
- PR unite (30g)
- 21
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Nessun modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di uutils/grep
-
grep - `-L` with `-m 0` or `-v ''` prints nothing; GNU still lists every fileForse già presa @yunusarda-sudo l’ha presa 5 giorni fa. Apertabug gnu-compat good first issue
Difficoltà 2/5 1-3 ore Idoneità per principianti 83/100
I maintainer di solito rispondono entro 2 giorni
-
grep - `-v -o` with `-A`/`-B`/`-C` prints nothing; GNU prints the matches found in the context linesApertabug gnu-compat good first issue
Difficoltà 2/5 1-3 ore Idoneità per principianti 83/100
I maintainer di solito rispondono entro 2 giorni
-
grep - interval counts above 32767 are accepted; GNU rejects them with `Regular expression too big`Forse già presa @yunusarda-sudo l’ha presa 5 giorni fa. Apertabug gnu-compat good first issue
Difficoltà 2/5 1-3 ore Idoneità per principianti 79/100
I maintainer di solito rispondono entro 2 giorni
-
grep - `--exclude-dir=./dir` does not exclude the operand `./dir`Forse già presa @yunusarda-sudo l’ha presa 5 giorni fa. Apertabug gnu-compat good first issue
Difficoltà 2/5 1-3 ore Idoneità per principianti 84/100
I maintainer di solito rispondono entro 2 giorni
-
bug gnu-compat good first issue
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
I maintainer di solito rispondono entro 2 giorni
Issue simili
-
marketing
Difficoltà 2/5 Mezza giornata Idoneità per principianti 62/100
I maintainer di solito rispondono entro 1 giorno
-
S: Untriaged T: Bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
libnyanpasu/clash-nyanpasu#6537 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 Meno di un'ora Idoneità per principianti 62/100
tauri-apps/tao#1445 ·
I maintainer di solito rispondono entro 1 giorno
-
bug P3
Difficoltà 1/5 1-3 ore Idoneità per principianti 88/100
-
go good first issue test
Difficoltà 2/5 1-3 ore Idoneità per principianti 88/100
I maintainer di solito rispondono entro 2 giorni