sed - script parser skips CR, VT, FF (and 0x85, 0xA0) as blanks; GNU skips only space and tab

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

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

@Himanshu-singh04 がすでに取り組んでいます。

2026年11月10日 から。

  • #665 @Himanshu-singh04 による — オープン

評価

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

調査の方向性

src/sed/script_char_provider.rsを読み、特にissueで空白文字の処理箇所として示されているScriptCharProvider::eat_spacesを確認してください。まず既存のsedパーサーテストを確認し、issueの例に従って、コマンドの後のキャリッジリターンと1行テキスト内の垂直タブをテストに追加してください。これらの入力がGNU sedと同じ動作をし、テストが通れば完了です。

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

説明

bug gnu-compat good first issue oss-scanner

Wherever the script parser skips blanks (between address and command, after a command, before
one-line a/i/c text, before a w/r file name, ...), GNU sed skips only space and tab.
uutils sed skips every Unicode whitespace character, including carriage return, vertical tab,
form feed and the raw bytes 0x85 and 0xA0. As a result:

  • a script saved with CRLF line endings runs here, where GNU stops with
    extra characters after command;
  • a leading \v, \f or \r is silently dropped from one-line a/i/c text and from
    file names.

Reproduction

Rust (incorrect)

$ printf 'a\n' | ./target/release/sed $'p\r'
a
a
# Exit code: 0

$ printf 'a\n' | ./target/release/sed $'1a\vfoo' | od -An -c
   a  \n   f   o   o  \n
# Exit code: 0

GNU (correct)

$ printf 'a\n' | /usr/bin/sed $'p\r'
/usr/bin/sed: -e expression #1, char 2: extra characters after command
# Exit code: 1

$ printf 'a\n' | /usr/bin/sed $'1a\vfoo' | od -An -c
   a  \n  \v   f   o   o  \n
# Exit code: 0

Root cause

ScriptCharProvider::eat_spaces in src/sed/script_char_provider.rs:64-69:

/// Advances the position past any whitespace characters.
pub fn eat_spaces(&mut self) {
    while self.pos < self.line.len() && self.current().is_whitespace() {
        self.advance();
    }
}

current() maps each byte to a char, so char::is_whitespace is also true for the bytes
0x85 and 0xA0 (U+0085, U+00A0).

Test

#[test]
fn test_carriage_return_after_command_rejected() {
    new_ucmd!()
        .arg("p\r")
        .pipe_in("a\n")
        .fails()
        .code_is(1);
}

#[test]
fn test_vertical_tab_kept_in_one_line_text() {
    new_ucmd!()
        .arg("1a\x0bfoo")
        .pipe_in("a\n")
        .succeeds()
        .stdout_is("a\n\x0bfoo\n");
}

Reported by Anthropic's OSS Scanner (ANT-2026-Q3PRSLF7).

主要言語
Rust
スター
123
フォーク
53
平均マージ
2日 8時間
マージ済み PR(30日)
40

環境構築

はじめの一歩

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

uutils/sed のほかの issue

uutils/sed の issue をすべて見る

似ている issue

Rust の issue をもっと見る

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

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