grep - regex syntax errors print Oniguruma's wording instead of GNU's messages
Los mantenedores suelen responder en 2 días
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 2/5
- Tiempo estimado
- 1-3 horas
- Aptitud para principiantes
- 75/100
Línea de trabajo
Empieza en src/matcher.rs, en CompiledPattern::compile y su alternativa compile_with; después, examina la traducción existente de errores de regex y las pruebas cercanas. Añade cobertura para los casos de redacción de GNU enumerados en el issue y ejecuta las pruebas de grep que ejercitan estos argumentos. El trabajo está terminado cuando los errores de sintaxis enumerados producen una salida stderr compatible con GNU, conservan el código de salida 2 y dejan stdout vacío.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
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).
- Lenguaje dominante
- Rust
- Estrellas
- 147
- Forks
- 34
- Merge medio
- 3 d 18 h
- PR fusionados (30 d)
- 21
Preparar el entorno
- Sin Dockerfile ni archivo de Docker Compose
- Sin plantilla de pull request
- Leer la guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de uutils/grep
-
grep - `-L` with `-m 0` or `-v ''` prints nothing; GNU still lists every filePosiblemente ocupada @yunusarda-sudo la tomó hace 5 días. Abiertobug gnu-compat good first issue
Dificultad 2/5 1-3 horas Aptitud para principiantes 83/100
Los mantenedores suelen responder en 2 días
-
grep - `-v -o` with `-A`/`-B`/`-C` prints nothing; GNU prints the matches found in the context linesAbiertobug gnu-compat good first issue
Dificultad 2/5 1-3 horas Aptitud para principiantes 83/100
Los mantenedores suelen responder en 2 días
-
grep - interval counts above 32767 are accepted; GNU rejects them with `Regular expression too big`Posiblemente ocupada @yunusarda-sudo la tomó hace 5 días. Abiertobug gnu-compat good first issue
Dificultad 2/5 1-3 horas Aptitud para principiantes 79/100
Los mantenedores suelen responder en 2 días
-
grep - `--exclude-dir=./dir` does not exclude the operand `./dir`Posiblemente ocupada @yunusarda-sudo la tomó hace 5 días. Abiertobug gnu-compat good first issue
Dificultad 2/5 1-3 horas Aptitud para principiantes 84/100
Los mantenedores suelen responder en 2 días
-
bug gnu-compat good first issue
Dificultad 2/5 1-3 horas Aptitud para principiantes 82/100
Los mantenedores suelen responder en 2 días
Todos los issues de uutils/grep
Issues similares
-
marketing
Dificultad 2/5 Medio día Aptitud para principiantes 62/100
Los mantenedores suelen responder en 1 día
-
S: Untriaged T: Bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
libnyanpasu/clash-nyanpasu#6537 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 Menos de una hora Aptitud para principiantes 62/100
tauri-apps/tao#1445 ·
Los mantenedores suelen responder en 1 día
-
bug P3
Dificultad 1/5 1-3 horas Aptitud para principiantes 88/100
-
go good first issue test
Dificultad 2/5 1-3 horas Aptitud para principiantes 88/100
Los mantenedores suelen responder en 2 días