Skip to content

fix(parser): skip backquote groups whole in procsub paren matchers (Refs #3354) - #3431

Merged
caomengxuan666 merged 4 commits into
masterfrom
fix/3354-procsub-backquote-paren
Nov 12, 2026
Merged

caomengxuan666 merged 4 commits into
masterfrom
fix/3354-procsub-backquote-paren

Conversation

@caomengxuan666

Copy link
Copy Markdown
Member

根因

嵌入式进程替换跨度提取的括号匹配器(embedded_procsub_close,src/parser/process_substitution.rs;其字节孪生 skip_procsub_paren,src/parser/token_actions.rs)对 backquote 组盲:组体内未配平的 ( 直接计入深度,真闭合符永远配不平,整段跨度被漏认领;随后展开器把组体文本当作词层文本处理,连组体内的 backquote 都在外层被展开掉。组体内未配平的 " 以同机理腐蚀匹配器的引号状态,同样吞掉真闭合符。

GNU 锚点

  • subst.c:1311 extract_process_subst → xparse_dolparen(parse.y:4686):跨度体由真正的解析器重解析;
  • parse.y:3877 parse_matched_pair:嵌套替换单元(含 backquote 组)经 shellquote 臂整段当作单位消费。
  • backquote 组内的 ( 是内层命令文本的数据,绝不是外层跨度的嵌套层级。

修法

两个匹配器现都把 backquote 组整段跳过:字符版复用 PR #3351 已有的 backquote_group_end(转发 lexer skip_backtick_corrected);字节版新增其孪生 skip_backtick_bytes(与 skip_backtick_corrected 同规则:反斜杠携带下一字节,首个其余 backquote 闭合)。两处门限均为 !single(与本文件内同族扫描一致:backquote 组在双引号内仍有效);未闭合的组回落到原逐字行走。

回归钉

tests/issue3354_procsub_backquote_paren.rs,6 格,期望以 GNU bash 5.3.20 实测为准:

格 内容 基底 本头
01 issue 形态:赋值 RHS,组内未配平 ( 红 绿
02 词首形态对照(GNU 与基底一致) 绿 绿
03 复合赋值面(skip_procsub_paren) 红 绿
04 组内配平括号守卫 绿 绿
05 转义 backquote 守卫 绿 绿
06 组内未配平 " 的引号状态面 红 绿

验证

  • 新钉:基底 3/6、头部 6/6(scrubbed_cargo.py cargo test --locked --test issue3354_procsub_backquote_paren)。
  • 全量 lib:头部 1246 passed / 0 failed / 4 ignored,与基底(同一提交 685ccbc4 的 worktree)逐数对齐。
  • 邻茎:issue3337 8/8、issue339_340 10/10、issue1561 9/9、issue1523 6/6、issue1690 1/1。
  • RUSTFLAGS="-D warnings" cargo check --locked --lib --bins rc=0;rustfmt --check(三分文件)净;marker-lint rc=0;UTF-8 边界卫生 rc=0。
  • 探针(~/workspace/fix-3354/probes/):GNU 5.3.20 与本头在复现形态上逐字一致([pre/dev/fd/63post] cap=[hello],内层 comsub 语法错误诊断两边相同、非分歧点)。

本 PR 删除了什么

无。纯加法修法:两处匹配器各加一个 backquote 跳过臂(+59 行产品代码),新增一个 6 格回归钉文件。未删任何函数、分支、测试或公开面;未改 docs/api-ledger.md;未碰 src/lexer/continuation.rs。

UNVERIFIED-BY-CAPTAIN

队长复核前未验证。REPORT 见车道工作区根 REPORT.md(不入仓)。

Refs #3354

…efs #3354)

Root cause: the embedded process-substitution span matchers
(`embedded_procsub_close` in parser/process_substitution.rs and
its byte twin `skip_procsub_paren` in parser/token_actions.rs)
counted parens straight through backquote groups. An unmatched
`(` inside a backquote group inflated the depth, so the true
closer never balanced and the whole span went unclaimed; the
expander then treated the body as word-level text and expanded
away even the backquote group inside it. An unmatched `"` inside
the group corrupted the walker's quote state the same way.

GNU anchor: subst.c:1311 `extract_process_subst` hands the span
to `xparse_dolparen` (parse.y:4686), which re-parses the body
with the real parser, and parse.y:3877 `parse_matched_pair`
consumes nested substitution units -- including backquote groups,
via the shellquote arm -- whole. A `(` inside a backquote group
is data for the inner command text, never a nesting level of the
outer span.

Fix: both matchers now skip a backquote group whole -- the char
matcher reuses the existing `backquote_group_end` walker (PR
#3351); the byte matcher gains its twin `skip_backtick_bytes`
(same rules as the lexer's `skip_backtick_corrected`). Gate is
`!single` only in both, matching the sibling scans: a backquote
group stays active inside double quotes. An unclosed group falls
through to the plain walk.

Regression pins (tests/issue3354_procsub_backquote_paren.rs, 6
tests, GNU bash 5.3.20 expectations): 01 issue shape (assignment
RHS), 02 word-initial control, 03 compound-assignment face
(`skip_procsub_paren`), 04 balanced-paren guard, 05 escaped-
backquote guard, 06 unmatched-dquote quote-state face. Base:
3 passed / 3 failed (01, 03, 06 red); head: 6 passed.
@caomengxuan666

Copy link
Copy Markdown
Member Author

队长复核完成:PASS(无作者侧前置,可合入)。

修法:两处 procsub 括号匹配器现把 backquote 组整段跳过——字符版复用
PR #3351 的 backquote_group_end,字节版新增同规则孪生 skip_backtick_bytes;
门限 !single,未闭合组回落原逐字行走。纯加法(产品 +59 行),未碰
continuation.rs,未改 api-ledger。

复核员亲跑(非车道自报转述):

  • 钉 issue3354_procsub_backquote_paren:本头 6/6;基底顶补 3/6,
    红恰 01/03/06——fail-first 逐名兑现。
  • 三方探针(GNU bash 5.3.20 / 基底 / 本头):复现、矩阵、引号三脚本,
    本头与 GNU 逐字一致(仅 /dev/fd 数字随分配顺序浮动);基底分歧恰为 issue 所述。
  • lib 双边:1246 passed / 0 failed / 4 ignored,两边逐数对齐,失败名集皆空。
  • 邻茎:issue3337 8/8、issue339_340 10/10、issue1561 9/9、issue1523 6/6、issue1690 1/1。
  • RUSTFLAGS="-D warnings" cargo check --all-targets:rc=0,1479 次 rustc 调用,
    0 警告 0 错误;fmt、marker-lint、UTF-8 卫生全绿。
  • GNU 锚点逐条核实:subst.c:1311 → xparse_dolparen(parse.y:4686)、
    parse.y:3877 parse_matched_pair。
  • 真分叉点 685ccbc4;对活尖 52eee03f 的区间交集 ∅。
  • CI 11 腿全绿(含 goldens 与双 cross-target)。明说:CI 的 nextest 精选表
    不含新钉 stem(两代日志全文 grep issue3354 为 0;见 CI 不跑新回归钉 stem:Rust tests 只跑精选 nextest 表 #3430),钉面以本复核亲跑为准。

附带裁断(卷宗 §11):车道建议的 skip_dollar_paren 同系盲点已实测——
( 面三方一致、证伪;" 面($(echo \echo "x`...)`)为真分歧,
但基底同病、非本 PR 回归,建议独立立案(最小复现与 GNU 实测见卷宗),不 fold 入本单。

合入条件见卷宗 §10:gh pr ready 后按既备正文 squash(唯一 Fixes #3354),
开工按当时活尖重算交集。

卷宗:~/workspace/review-3431/CAPTAIN-VERIFY.md

@caomengxuan666
caomengxuan666 marked this pull request as ready for review November 12, 2026 15:11
@caomengxuan666
caomengxuan666 merged commit 3ef22b8 into master Nov 12, 2026
11 checks passed
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