sed - with `-s` or `-i`, the file read by `R` is not restarted for each input file
メンテナーはふだん 1 日以内に返信
評価
調査の方向性
src/sed/named_reader.rs と、src/sed/processor.rs の process_all_files 周辺にあるリセット処理から始め、個別の入力ファイルの開始時に context.named_readers がどのように処理されるか確認してください。issue にあるもののような回帰テストを追加するか使用し、それを実行して、-s と -i を指定した場合に R コマンドが各ファイルのヘッダーの先頭行を読み込むことを確認してください。
索引モデルが issue の本文から書いたものです。
説明
With -s (separate) or -i (which implies separate files), GNU sed restarts every file read by
the R command at the beginning of each input file. uutils sed keeps one cursor for the whole
run, so sed -i '1R header' f1 f2 inserts the first line of header into f1 and the second
line into f2; once header is used up, later files get nothing. Without -s/-i both
implementations agree.
Reproduction
$ printf 'h1\nh2\n' > hdr; printf 'a\n' > fa; printf 'b\n' > fb
Rust (incorrect)
$ ./target/release/sed -s '1R hdr' fa fb
a
h1
b
h2
# Exit code: 0
GNU (correct)
$ /usr/bin/sed -s '1R hdr' fa fb
a
h1
b
h1
# Exit code: 0
Root cause
NamedReader (src/sed/named_reader.rs) only moves forward: Unopened -> Open ->
Exhausted, with no way to go back. process_all_files resets per-file state when a new
separate file starts (src/sed/processor.rs:995-1002), but not the named readers:
if context.separate || index == 0 {
context.line_number = 0;
reset_latched_address_ranges(&mut context.range_commands);
// Reset hold space for separate file processing
context.hold.content.clear();
context.hold.has_newline = true;
}
The readers live in context.named_readers (src/sed/command.rs:75).
Test
#[test]
fn test_r_command_restarts_for_each_separate_file() {
let temp_dir = assert_fs::TempDir::new().unwrap();
let header = temp_dir.child("header");
header.write_str("first\nsecond\n").unwrap();
let one = temp_dir.child("one");
one.write_str("x\n").unwrap();
let two = temp_dir.child("two");
two.write_str("y\n").unwrap();
new_ucmd!()
.args(&[
"-s",
&format!("1R {}", header.path().display()),
one.path().to_str().unwrap(),
two.path().to_str().unwrap(),
])
.succeeds()
.stdout_is("x\nfirst\ny\nfirst\n");
}
Reported by Anthropic's OSS Scanner (ANT-2026-D4GHQSKO).
- 主要言語
- Rust
- スター
- 123
- フォーク
- 53
- 平均マージ
- 2日 8時間
- マージ済み PR(30日)
- 40
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートなし
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
uutils/sed のほかの issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
メンテナーはふだん 1 日以内に返信
-
sed - with `--posix`, `-e 'i\'` takes the next `-e` as its text対応中かも @yunusarda-sudo が 14 日前に担当しました。 オープンbug gnu-compat good first issue
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
メンテナーはふだん 1 日以内に返信
-
sed - script parser skips CR, VT, FF (and 0x85, 0xA0) as blanks; GNU skips only space and tab対応中かも @Himanshu-singh04 が 22 日前に担当しました。 オープンbug gnu-compat good first issue oss-scanner
難易度 2/5 1〜3時間 初心者へのやさしさ 89/100
メンテナーはふだん 1 日以内に返信
-
sed - output already produced is lost when a runtime error stops processing対応中かも @Himanshu-singh04 が 21 日前に担当しました。 オープンbug gnu-compat good first issue oss-scanner
難易度 2/5 1〜3時間 初心者へのやさしさ 86/100
メンテナーはふだん 1 日以内に返信
-
sed - unknown POSIX class names like `[[:foo:]]` or `[[:word:]]` are accepted instead of rejected対応中かも @draarivpatel-ui が 7 日前に担当しました。 オープンbug gnu-compat good first issue oss-scanner
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
メンテナーはふだん 1 日以内に返信
似ている issue
-
autofix:working
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
-
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
libracoder/kiri#1138 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 83/100
roc-lang/basic-webserver#277 ·
メンテナーはふだん 1 日以内に返信
-
enhancement
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
samkerrcode/opengent#113 ·
メンテナーはふだん 1 日以内に返信
-
app bug session
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
メンテナーはふだん 1 日以内に返信