awk: a `/` inside a bracket expression ends the regex literal

オープン 初心者向け
#173 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

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

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

評価

難易度
2/5
見積もり時間
1〜3時間
初心者へのやさしさ
85/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
awk, rust
領域
cli

調査の方向性

まず、awk パーサーが正規表現リテラルと角括弧式をどのように読み取るかを追い、その後、sub(/.*[/]/, "") と入力 usr/share/doc を使って、提示されたリグレッションケースを追加します。対象を絞ったテストを実行し、doc が出力されることを確認します。また、issue ではカバレッジの参照として GNU awk のテスト beginfile1 と regexpbrack も挙げられています。

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

説明

bug gnu-compat good first issue

Inside [...] a / is an ordinary character, so /a[/]b/ is a regex that
matches a/b. uutils awk ends the regex at the / inside the brackets and
then fails to parse the rest of the line. [/] is the usual way to match a
slash in paths (sub(/.*[/]/, "")).

Reproduction

Rust (incorrect)

$ ./target/release/awk 'BEGIN { print ("a/b" ~ /^a[/]b$/) }'
Error: Syntax error
   ╭─[ CLI:1:29 ]
 1 │ BEGIN { print ("a/b" ~ /^a[/]b$/) }
   │                             ╰── Missing closing parenthesis `(` in statement operand.

GNU (correct)

$ gawk 'BEGIN { print ("a/b" ~ /^a[/]b$/) }'
1

Test

#[test]
fn slash_in_regex_bracket() {
    ucmd()
        .arg("{ sub(/.*[/]/, \"\"); print }")
        .pipe_in("usr/share/doc\n")
        .succeeds()
        .stdout_only("doc\n");
}

Exposed by the GNU awk test suite: beginfile1, regexpbrack.

主要言語
Rust
スター
31
フォーク
13
平均マージ
23時間 42分
マージ済み PR(30日)
29

環境構築

このプロジェクトには開発コンテナ、Dockerfile、コントリビューションガイドがありません。まず README を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。

はじめの一歩

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

uutils/awk のほかの issue

uutils/awk の issue をすべて見る

似ている issue

Rust の issue をもっと見る

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

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