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

オープン
#203 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 2 日以内に返信

まだ誰も着手していません。

評価

難易度
3/5
見積もり時間
1〜2日
初心者へのやさしさ
68/100
issue の種類
バグ
明瞭さ
おおむね明確
活発さ
活発
技術スタック
rust
領域
backend, cli

調査の方向性

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.

索引モデルが issue の本文から書いたものです。

説明

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.

主要言語
Rust
スター
147
フォーク
34
平均マージ
3日 18時間
マージ済み PR(30日)
21

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

uutils/grep のほかの issue

uutils/grep の issue をすべて見る

似ている issue

Rust の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。