sed - with `--posix`, `-e 'i\'` takes the next `-e` as its text

未关闭 适合新手
#688 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

@yunusarda-sudo 已经在做这个了。

开始于 2026年11月17日。

  • #701 来自 @yunusarda-sudo —— 未关闭

评估

难度
2/5
预计耗时
1-3 小时
新手友好度
76/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃
技术栈
rust
领域
cli, testing

调研方向

首先阅读 GNU sed 测试 compile-errors 和 issue 中提到的代码 compile_text_command_posix,然后使用 --posix 运行提供的复现步骤。在表达式边界处,为 a\、i\ 和 c\ 添加所示的回归测试用例。完成标准是:POSIX 用例以退出码 1 和“incomplete command”失败,而 GNU 扩展用例仍然成功。

由索引模型根据 Issue 内容生成。

描述

bug gnu-compat good first issue

As a GNU extension, sed -e 'i\' -e hello uses the next -e fragment as the
text of a, i or c. With --posix, GNU sed does not join the fragments,
and an a\, i\ or c\ at the end of an -e is an incomplete command.
uutils sed joins them in both modes. The same text in one -f file (i\
followed by hello on the next line) is valid POSIX and works in both
implementations.

The GNU test compile-errors exposes this. Open PR #625 rewrites
compile_text_command_posix, but a build of it still accepts this case.

Reproduction

Rust (incorrect)

$ echo w | ./target/release/sed --posix -e 'i\' -e hello
hello
w
# Exit code: 0

GNU (correct)

$ echo w | sed --posix -e 'i\' -e hello
sed: -e expression #1, char 2: incomplete command
# Exit code: 1

$ echo w | sed -e 'i\' -e hello
hello
w
# Exit code: 0

Test

#[rstest]
#[case::append("a\\")]
#[case::insert("i\\")]
#[case::change("c\\")]
fn test_posix_text_command_stops_at_expression_end(#[case] cmd: &str) {
    new_ucmd!()
        .args(&["--posix", "-e", cmd, "-e", "second fragment"])
        .pipe_in("line\n")
        .fails()
        .code_is(1)
        .no_stdout()
        .stderr_contains("incomplete command");

    // GNU extension: without --posix the next fragment is the text.
    new_ucmd!()
        .args(&["-e", cmd, "-e", "second fragment"])
        .pipe_in("")
        .succeeds()
        .no_output();
}

Exposed by the GNU sed test suite: compile-errors.

主要语言
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 摘要。