Repository navigation
fix(read): match high-byte -d delimiter in its single-byte transport form (Refs #2662) - #3142
Merged
Merged
Conversation
…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.
caomengxuan666
marked this pull request as ready for review
November 9, 2026 07:58
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
180 单令第一波 M1 组车道 PR。本 PR 只承载 #2662 的修复与回归钉;同组 #2652、#2653 已完成诊断、因落点与在飞 PR 的 diff 文件表冲突按简报停手上报(诊断与修法设计在车道 REPORT 中),不在本 PR 修复面内。
#2662 根因
GNU bash 5.3 的
read -d分隔符是参数的第一个字节(builtins/read.def:385delim = (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 将单字节形收敛为共享 helperread_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_regressions4 红经源码核与本改动面无交集——全文无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