grep - the interval `{,}` (`\{,\}` in BRE) is rejected or read literally; GNU reads it as `{0,}`

Aperta
#203 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 2 giorni

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
3/5
Tempo stimato
1-2 giorni
Idoneità per principianti
68/100
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Attiva
Stack tecnologico
rust
Ambito
backend, cli

Direzione di ricerca

Start by locating the regex parsing and matching paths for basic and extended modes, then review the existing grep tests and the GNU bre test, especially Spencer BRE test #40. Add coverage for \{,\} and {,} matching zero or more occurrences, using the supplied reproduction and expected output. Done means both modes select the same lines as GNU grep and the regression test passes.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

bug gnu-compat good first issue

Known: closed PR #152 (closed by its author without merging) — https://github.com/uutils/grep/pull/152

GNU grep reads an interval with neither bound, {,}, as {0,} (the same as *). In basic
mode uu_grep rejects \{,\} with an Oniguruma error and exit 2; in extended mode it reads
{,} as literal text and so selects different lines. PR #152 rewrote the pattern text and
was closed; no issue tracks the behaviour.

Exposed by the GNU test bre (Spencer BRE test #40, a\{,\} must match a\{,\}).

Reproduction

Rust (incorrect)

$ printf 'mo\nmooo\n' | ./target/release/grep 'mo\{,\}'
grep: invalid pattern "mo\{,\}": invalid repeat range {lower,upper}
# Exit code: 2

$ printf 'mo\nmooo\n' | ./target/release/grep -E 'mo{,}'
# Output: (none)
# Exit code: 1

GNU (correct)

$ printf 'mo\nmooo\n' | LC_ALL=C /usr/bin/grep 'mo\{,\}'
mo
mooo
# Exit code: 0

$ printf 'mo\nmooo\n' | LC_ALL=C /usr/bin/grep -E 'mo{,}'
mo
mooo
# Exit code: 0

Test

#[test]
fn empty_interval_means_zero_or_more() {
    for args in [&["-c", "bz\\{,\\}"][..], &["-c", "-E", "bz{,}"][..]] {
        let (_s, mut c) = ucmd();
        c.args(args)
            .pipe_in("b\nbzzz\nq\n")
            .succeeds()
            .stdout_only("2\n");
    }
}

Exposed by the GNU grep test suite: bre.

Lingua principale
Rust
Stelle
147
Fork
34
Merge medio
3g 18h
PR unite (30g)
21

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di uutils/grep

Tutte le issue di uutils/grep

Issue simili

Altre issue su Rust

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.