grep - regex syntax errors print Oniguruma's wording instead of GNU's messages
メンテナーはふだん 2 日以内に返信
まだ誰も着手していません。
評価
調査の方向性
src/matcher.rs の CompiledPattern::compile と、そのフォールバックである compile_with から調べ始め、既存の正規表現エラーの変換処理と近くのテストを確認してください。issue に記載された GNU の文言ケースをカバーするテストを追加し、これらの引数を対象とする grep テストを実行してください。完了条件は、記載された構文エラーが GNU 互換の stderr を出力し、終了コード 2 を維持し、stdout が空であることです。
索引モデルが issue の本文から書いたものです。
説明
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).
- 主要言語
- Rust
- スター
- 147
- フォーク
- 34
- 平均マージ
- 3日 18時間
- マージ済み PR(30日)
- 21
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートなし
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
uutils/grep のほかの issue
-
grep - `-L` with `-m 0` or `-v ''` prints nothing; GNU still lists every file対応中かも @yunusarda-sudo が 5 日前に担当しました。 オープンbug gnu-compat good first issue
難易度 2/5 1〜3時間 初心者へのやさしさ 83/100
メンテナーはふだん 2 日以内に返信
-
grep - `-v -o` with `-A`/`-B`/`-C` prints nothing; GNU prints the matches found in the context linesオープンbug gnu-compat good first issue
難易度 2/5 1〜3時間 初心者へのやさしさ 83/100
メンテナーはふだん 2 日以内に返信
-
grep - interval counts above 32767 are accepted; GNU rejects them with `Regular expression too big`対応中かも @yunusarda-sudo が 5 日前に担当しました。 オープンbug gnu-compat good first issue
難易度 2/5 1〜3時間 初心者へのやさしさ 79/100
メンテナーはふだん 2 日以内に返信
-
grep - `--exclude-dir=./dir` does not exclude the operand `./dir`対応中かも @yunusarda-sudo が 5 日前に担当しました。 オープンbug gnu-compat good first issue
難易度 2/5 1〜3時間 初心者へのやさしさ 84/100
メンテナーはふだん 2 日以内に返信
-
bug gnu-compat good first issue
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
メンテナーはふだん 2 日以内に返信
似ている issue
-
marketing
難易度 2/5 半日 初心者へのやさしさ 62/100
メンテナーはふだん 1 日以内に返信
-
S: Untriaged T: Bug
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
libnyanpasu/clash-nyanpasu#6537 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1時間未満 初心者へのやさしさ 62/100
tauri-apps/tao#1445 ·
メンテナーはふだん 1 日以内に返信
-
bug P3
難易度 1/5 1〜3時間 初心者へのやさしさ 88/100
-
go good first issue test
難易度 2/5 1〜3時間 初心者へのやさしさ 88/100
メンテナーはふだん 2 日以内に返信