Skip to content

[bug] unix: lexer 行读取的 CRLF 容忍未门控——GNU 在 Linux 把 CR 当字面数据,rubash 静默吞掉(E17 第 4 处,已被 linux smoke 实证) #140

Closed

Description

@caomengxuan666

环境

rubash    e98d0e4d 首个真实 Linux 构建
对照      WSL GNU Bash 5.3.0
场景      linux smoke 首跑的副产物实证(docs/cross-platform-gap-ledger.md E17)

现象

CRLF 行尾的 shell 脚本,GNU 在 Linux 上按字面处理 CR:

/mnt/d/.../getopts.tests: line 16: $'getopts\r': command not found
/mnt/d/.../getopts.tests: line 20: $'\r': command not found

rubash 则静默接受并正常运行整个脚本(src/lexer/mod.rs:214 对脚本行
strip_suffix('\r'),同文件 :178 的注释自己写明 "GNU bash does NOT strip CR
from CRLF line endings")。Windows 侧这个容忍是产品决定(niubash#120 家族,
CRT 文本模式补偿,保留);unix 侧它是可观察的 GNU 偏差——首个被 83 套件
真实踩到的跨平台语义分叉。

触发/不触发

  • 触发:任何 CRLF 的 .sh/脚本文件在 Linux 上运行——GNU 报 $'\r': command not found,rubash 正常执行。
  • 现有 E17 门控(f12aa756 + 3b93b86)已把 comsub 捕获、read、read -t
    三处的 CR 剥离 cfg!(windows) 化;仅剩 lexer 行读取这一处未门控(并行
    开发期间文件被占用,当时留作 wave-2)。

期望

src/lexer/mod.rs:214 的行尾 CR 剥离(含 heredoc 体同规则处)加
cfg!(windows) 门控:unix 保留 CR 为字面数据(与 GNU 一致),Windows 行为
字节不变。注意 heredoc 体的同族逻辑一并处理,并补一条
printf 'a\r\n' | { read x; ... } 式的双平台回归。

关联

  • 台账:docs/cross-platform-gap-ledger.md E17(第 4 处站点,优先级因本实证上调)
  • 证据:target/issue-suites/results/linux-smoke/(LF 化前 GNU 侧全灭、rubash
    全跑的原始输出即本差异的现场)

Activity

  1. added
    bug
    platform:linux
    platform:macos
    on Sep 26, 2026
  2. caomengxuan666 commented on Sep 26, 2026

    @caomengxuan666
    MemberAuthor

    已在 cbfbebd 落地(7a2a1e5e):lexer 行读取(mod.rs:214)与 heredoc 体(~:518)的 strip_suffix('\r') 均加 cfg!(windows) 门(对齐 E17 的 3b93b86 模式);Windows 侧 CRLF fixture 字节比对证明不变;unix 侧新增 #[cfg(unix)] 回归(CRLF heredoc 定界符永不匹配→EOF 标记体)+ windows 对偶测试。

  3. added a commit that references this issue on Oct 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugplatform:linuxplatform:macos

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions