Skip to content

fix(read): match high-byte -d delimiter in its single-byte transport form (Refs #2662) - #3142

Merged
caomengxuan666 merged 3 commits into
masterfrom
fix/M1-wave1
Nov 9, 2026
Merged

caomengxuan666 merged 3 commits into
masterfrom
fix/M1-wave1

Conversation

@caomengxuan666

@caomengxuan666 caomengxuan666 commented Nov 8, 2026 •

Copy link
Copy Markdown
Member

180 单令第一波 M1 组车道 PR。本 PR 只承载 #2662 的修复与回归钉;同组 #2652、#2653 已完成诊断、因落点与在飞 PR 的 diff 文件表冲突按简报停手上报(诊断与修法设计在车道 REPORT 中),不在本 PR 修复面内。

#2662 根因

GNU bash 5.3 的 read -d 分隔符是参数的第一个字节(builtins/read.def:385 delim = (unsigned char)*list_optarg,比较在 read.def:834)。rubash 的文本域记录扫描只测分隔符的两种传输形:多字节 needle(分隔符字符 UTF-8 字节的 marker 对)与字面字符。但字节 locale 下 U+0080..=U+00FF 分隔符对应的原始流字节在文本域里走的是单字节 marker 形(bytes_to_shell_text(&[byte])),四个扫描点从未测这一形,分隔符永不命中:

  • read_function_stdin 的 scan_record(src/executor/read_io.rs)——管道/FUNCTION_STDIN 镜像路径,首读即 EOF、循环体不执行;
  • slurped_record_eof_no_delimiter(src/executor/read_helpers.rs)——slurp 传输的 EOF 判定;
  • find_unescaped_read_delimiter(read_helpers.rs)——非 raw 读的切分点;
  • trim_read_input_literal 的 raw 分支切分(read_helpers.rs)。

已有两个站点(record_contains_delimiter、unescaped_delimiter_index)内联测了三形,本 PR 将单字节形收敛为共享 helper read_delimiter_single_form 并补齐四个缺口站点。

回归钉

tests/issue2662_read_high_byte_delimiter.rs:12 格(脚本文件形态、LC_ALL=C、stdout+退出码逐字节断言;期望值以 GNU bash 5.3.20 oracle 实测)。基底树 fail-first:9 红 / 3 绿,红格恰为缺陷格,对照格(NUL 分隔符、普通文件重定向、0x1b 载体字节分隔符)基底即绿。头树:钉 12/0、lib 1206/0/4、邻茎 27 条中 26 条全绿(issue353_ansi_u_readtime_locale_regressions 4 红经源码核与本改动面无交集——全文无 read -d、改动对非高字节分隔符逐点等价——判基底/环境形)、RUSTFLAGS="-D warnings" 检查通过、marker-lint 通过、fmt 通过。

已知残余(不在本 PR 面内,已在车道 REPORT 中停手上报)

分隔符字节与流中后续数据字节恰成合法 UTF-8 序列时(如 -d $'\303\251' 且流中 0xC3 后跟 0xA9 数据),传输文本(bytes_to_shell_text,substitution_metadata.rs:690)把该序列存为一个字面字符,分隔符字节在文本域无任何形态可匹配——这是传输编码的分块敏感性与字节位置消费者之间的不变量问题,忠实修复需动传输编码/记录重组,超出本车道面。钉中对应格已改为「参数首字节规则 + 流中孤立分隔符字节」形态;joined 形态的完整证据与修法选项在车道 REPORT 的 #2662 残余节。

本 PR 删除了什么

删除了 record_contains_delimiter 与 unescaped_delimiter_index 中各自内联的单字节形计算,收敛到共享 helper;无其他删除,无行为面收缩。

Refs #2662

…form (Refs #2662)

GNU builtins/read.def:385 takes the -d delimiter as the first byte of
the argument and read.def:834 compares it byte-wise. rubash's
text-domain record scans tested only two of the delimiter's three
transport forms — the marker-pair needle of the delimiter char's
UTF-8 encoding and the literal char — but a byte-locale delimiter in
U+0080..=U+00FF travels in the stream text as the single-byte marker
pair of the raw byte itself, so the delimiter never matched: the
first read over the buffered transports reported EOF and the record
was lost.

Add one shared form computation (read_delimiter_single_form) and one
combined matcher (read_delimiter_match_len: needle, then single-byte
form, then literal — the order the split chains already used), and
route the four scans that missed the form through it:
read_function_stdin's scan_record (read_io.rs),
slurped_record_eof_no_delimiter, find_unescaped_read_delimiter and
the raw split in trim_read_input_literal (read_helpers.rs). The two
scans that already tested the form inline
(record_contains_delimiter, unescaped_delimiter_index) now share the
helper.

Pin: tests/issue2662_read_high_byte_delimiter.rs, 12 cells measured
byte-exact against GNU bash 5.3.20 under LC_ALL=C — base 9 red /
3 green (controls), head 12/0. One cell pins the first-byte rule for
a multibyte -d argument with the delimiter byte standalone in the
stream; the joined-stream variant (delimiter byte forming a valid
UTF-8 sequence with following data bytes in the transport text) is a
separate transport-encoding residual, documented in the lane report.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant