Skip to content

fix: single-quoted backslash is data in quoted-IFS marking (Refs #2830) - #2994

Merged
caomengxuan666 merged 2 commits into
masterfrom
fix/2830-eval-continuation
Nov 7, 2026
Merged

caomengxuan666 merged 2 commits into
masterfrom
fix/2830-eval-continuation

Conversation

@caomengxuan666

Copy link
Copy Markdown
Member

Refs #2830

问题与根因

modernish 的 init eval 字符串在 rubash 上是语法错误(eval: line 2042: syntax error near unexpected token '\ '),is() 未定义,389 个测试一个都跑不起来;GNU 侧 380 ok。

根因不在 eval 也不在续行收集,而在复合词的引号 IFS 标记通道 mark_quoted_ifs_from_raw(src/executor/command_prepare.rs):它模拟去引号过程、记录引号内 IFS 字节的位置,再给展开词打 \x1c 保护标记。该模拟的 \ 臂在单引号段内把反斜杠与下一个字节成对吞掉,造成两类错误:

  1. 下一字节是 IFS 字节(空格/制表/换行/自定义 IFS 字符)时,它的位置从未被记录 → 展开后在引号内部发生字段劈分。'( a | b \<换行>| c)'${V:+} 被劈成 ( a | b \ 与 | c) 两场;作为 eval 实参时,eval 以空格拼接两场,制造出 \ 伪记号——即 modernish 的死点形态。
  2. 下一字节是 $ / 反引号 / " 时,模拟写入的是原字节而去引号 walk 写的是载体字节(DATA_DOLLAR 等),模拟与 cooked 词不等 → 整个标记通道放弃 → 同段内其它引号 IFS 字节一并失去保护;下一字节是 '(段结束引号)时同理错位。

GNU 语义:string_extract_single_quoted 以 allowesc=0 被调用(subst.c:1088、subst.c:11887),单引号段内反斜杠不转义、不吞字节;抽出的段经 add_quoted_string/quote_string(subst.c:11862、subst.c:4773)逐字节 CTLESC 保护——段内每个 IFS 字节都不可劈分,与其前一字节无关。parse.y:5376-5383 亦明示 \<newline> 仅在单引号内保留为数据对。

改动

mark_quoted_ifs_from_raw 的单引号 \ 臂改为逐字节处理:只消费反斜杠本身(并按引号内数据记录其 IFS 位置),下一字节回到它正常的单引号臂——IFS 字节被记录、触发字节写载体、结束引号正常闭合。命令词与 for 词两条调用路径共用此函数,一并受益。纯引号词、赋值 RHS、双引号后缀等既有正确形态不变(钉中含对照组)。

新增回归钉 tests/issue2830_eval_continuation_regressions.rs(5 例):最小劈分形状 × 参数/命令替换/反引号后缀 × 默认与自定义 IFS、for 词、触发字节污染、eval case 模式表续行(最小形 + modernish 形)、对照组。

与 #2876 的关系:同属 eval 面,但 #2876 的根因是 extglob parse gate / eval 串形状扫描(src/lexer/skip.rs、src/executor/trap_exec.rs),与本单的标记模拟不是同一机制,本单不触碰其修复面。

验证(车道自验,UNVERIFIED-BY-CAPTAIN)

  • fail-first:钉在 master b3e4ff89 上 1 passed / 4 failed;修后 5 passed / 0 failed。
  • 全量 lib:1188 passed / 0 failed / 4 ignored,与 base 逐数一致。
  • RUSTFLAGS="-D warnings" cargo check --locked --lib --bins rc=0;UTF-8 hygiene clean;两改动文件 rustfmt clean。
  • parser/eval 邻域 stem 8 个全绿(issue2876/issue1114/issue1013/issue124/issue153/a3_f3/assignment_quote_roundtrip/array_compound_quote,共 50 例)。
  • 探针矩阵 33 形与 GNU bash 5.3.20 逐字节一致(含 eval2 最小化、t5 骨架、for 词、自定义 IFS)。
  • modernish 真资产链路:base 全套件死于 bin/modernish: eval: line 2042 原死点(rc=128,0 测试);修后 init 完成(--version 正常、is 已定义),--test 越过 init 进入测试阶段,后死于 sys/cmd/harden 模块初始化——该面(harden.mm:161-163 转义保留字 case 模式表)在 base 二进制上同形同错,属既有独立缺陷,非本单引入,未在本 PR 处理(详见车道 REPORT)。

本 PR 删除了什么

删除了标记模拟中「单引号段内反斜杠成对吞字节」这一错误不变量(src/executor/command_prepare.rs 内 7 行替换为 11 行逐字节臂,含 GNU 锚点注释);无其它删除。净行数:生产代码 +11/−7,新增测试文件 +145 行,合计 +156/−7。

mark_quoted_ifs_from_raw simulated quote removal to record which IFS
bytes sit inside quotes, but its backslash arm consumed a single-quoted
backslash together with the following byte as a pair. An IFS byte after
the backslash was never recorded and field-split inside the quoted span
('( a | b \<newline>| c)'${V:+} became two fields; as an eval argument
the rejoin manufactured the `\ ` token that killed modernish's init
eval at bin/modernish:2042). A following $, backtick or " desynced the
simulation from the cooked word and bailed the whole marking pass.

GNU calls string_extract_single_quoted with allowesc=0 (subst.c:1088,
subst.c:11887): inside single quotes a backslash neither escapes nor
consumes the next byte, and quote_string (subst.c:4773) protects the
extracted span byte-by-byte. Consume only the backslash and let the
next byte take its normal single-quoted arm.

Pins: tests/issue2830_eval_continuation_regressions.rs (fail-first on
master 1 passed / 4 failed; after the fix 5/5, full lib 1188/0/4
unchanged). Distinct mechanism from #2876 (extglob gate / eval shape
scan); that fix surface is untouched.
@caomengxuan666
caomengxuan666 marked this pull request as ready for review November 7, 2026 15:30
@caomengxuan666

Copy link
Copy Markdown
Member Author

队长复核通过,准备合入。

  • 复核面:head 84af0815,恰 2 文件(src/executor/command_prepare.rs +11/−7、新钉 stem +145);无 REPORT.md 入仓、无 ledger、未碰 continuation.rs(根因在下游标记模拟,非词法器——与简报假设不同,车道定性正确)。
  • 队长全套(review clone、构建槽、完整日志):钉 5 passed / 0 failed(独立 test result 行);全量 lib 1188/0/4,与 base b3e4ff89 逐数一致;RUSTFLAGS="-D warnings" rc=0;hygiene rc=0;逐文件 rustfmt rc=0;debug 二进制构建 rc=0。
  • modernish 真资产点检(队长亲跑,vendored 63bdae02、净化 env、车道 init-check):base 对照二进制死于立案死点——eval: line 2042: syntax error near unexpected token '\ '、is 未定义;本 PR 头二进制 init 完成、is 已定义,与 GNU 同头条。eval2 最小片段与 GNU 逐字节同(stdout/stderr/rc 全同)。
  • 一条观察(不拦合入、未立单):手搓 init-check 里故意写错的 is file /etc/hostname(file 非 modernish 算子)在 GNU 下 die 指向 $2、本二进制指向 $1——is() 的 $# 分派骨架最小复刻在两壳逐字节同,故普通函数分派不是机制;modernish 按能力探针拼装函数体,属待查面,记入 [test] modernish: re-run the full bin/modernish --test chain on current master (blockers #2511/#2493 closed) #2902 收官链探针清单(此面此前被 [parser] 长 eval 串内 case 模式表反斜杠续行解析失败(modernish 初始化残废) #2830 死点遮住)。
  • 车道报告的两张新面(comsub 后缀反斜杠折叠、harden.mm 转义保留字 case 模式表)合入后由队长分别立单,后者即 [test] modernish: re-run the full bin/modernish --test chain on current master (blockers #2511/#2493 closed) #2902 的下一站。

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