sed - with `-s` or `-i`, the file read by `R` is not restarted for each input file
Maintainer thường phản hồi trong vòng 1 ngày
Đánh giá
- Độ khó
- 2/5
- Thời gian dự kiến
- 1-3 giờ
- Mức phù hợp với người mới
- 84/100
Hướng nghiên cứu
Bắt đầu với src/sed/named_reader.rs và logic đặt lại trong src/sed/processor.rs quanh process_all_files; kiểm tra cách xử lý context.named_readers khi các tệp đầu vào riêng biệt bắt đầu. Thêm hoặc dùng một bài kiểm thử hồi quy như bài trong issue, rồi chạy để xác nhận lệnh R đọc dòng đầu tiên của phần đầu tệp cho mỗi tệp với -s và -i.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
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).
- Ngôn ngữ chính
- Rust
- Star
- 123
- Fork
- 53
- Merge trung bình
- 2 ngày 8 giờ
- Pull request đã merge (30 ngày)
- 40
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Không có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của uutils/sed
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
Maintainer thường phản hồi trong vòng 1 ngày
-
sed - with `--posix`, `-e 'i\'` takes the next `-e` as its textCó thể đã có người làm @yunusarda-sudo đã nhận 14 ngày trước. Đang mởbug gnu-compat good first issue
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
Maintainer thường phản hồi trong vòng 1 ngày
-
sed - script parser skips CR, VT, FF (and 0x85, 0xA0) as blanks; GNU skips only space and tabCó thể đã có người làm @Himanshu-singh04 đã nhận 22 ngày trước. Đang mởbug gnu-compat good first issue oss-scanner
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 89/100
Maintainer thường phản hồi trong vòng 1 ngày
-
sed - output already produced is lost when a runtime error stops processingCó thể đã có người làm @Himanshu-singh04 đã nhận 21 ngày trước. Đang mởbug gnu-compat good first issue oss-scanner
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 86/100
Maintainer thường phản hồi trong vòng 1 ngày
-
sed - unknown POSIX class names like `[[:foo:]]` or `[[:word:]]` are accepted instead of rejectedCó thể đã có người làm @draarivpatel-ui đã nhận 7 ngày trước. Đang mởbug gnu-compat good first issue oss-scanner
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
uutils/sed#646 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
Issue tương tự
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 83/100
roc-lang/basic-webserver#277 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
enhancement
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
samkerrcode/opengent#113 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
app bug session
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
Maintainer thường phản hồi trong vòng 1 ngày
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 64/100
Maintainer thường phản hồi trong vòng 1 ngày
-
backlog
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
sagemathinc/sagebrush#3415 ·
Maintainer thường phản hồi trong vòng 1 ngày