Repository navigation
fix: single-quoted backslash is data in quoted-IFS marking (Refs #2830) - #2994
Merged
Merged
Conversation
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
marked this pull request as ready for review
November 7, 2026 15:30
Member
Author
|
队长复核通过,准备合入。
|
This was referenced Nov 7, 2026
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.
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保护标记。该模拟的\臂在单引号段内把反斜杠与下一个字节成对吞掉,造成两类错误:'( a | b \<换行>| c)'${V:+}被劈成( a | b \与| c)两场;作为eval实参时,eval 以空格拼接两场,制造出\伪记号——即 modernish 的死点形态。$/ 反引号 /"时,模拟写入的是原字节而去引号 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)
b3e4ff89上 1 passed / 4 failed;修后 5 passed / 0 failed。RUSTFLAGS="-D warnings" cargo check --locked --lib --binsrc=0;UTF-8 hygiene clean;两改动文件 rustfmt clean。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。