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

未关闭 适合新手
#654 0 条评论 0 个 reaction 已指派 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,尤其是 ScriptCharProvider::eat_spaces;issue 指出了空白字符处理的位置。先检查现有的 sed 解析器测试,并按照 issue 中的示例,添加对命令后的回车符和单行文本中的垂直制表符的测试覆盖。完成标准是这些输入的行为与 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 小时
30 天内合并 PR
40

环境准备

  • 没有 Dockerfile 或 Docker Compose 文件
  • 没有 Pull Request 模板
  • 阅读贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

uutils/sed 的其他 Issue

查看 uutils/sed 的全部 Issue

相似的 Issue

更多 Rust Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。