Repository navigation
fix(parser): skip backquote groups whole in procsub paren matchers (Refs #3354) - #3431
Merged
Merged
Conversation
…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.
This was referenced Nov 12, 2026
Member
Author
|
队长复核完成:PASS(无作者侧前置,可合入)。 修法:两处 procsub 括号匹配器现把 backquote 组整段跳过——字符版复用 复核员亲跑(非车道自报转述):
附带裁断(卷宗 §11):车道建议的 合入条件见卷宗 §10: 卷宗: |
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.
根因
嵌入式进程替换跨度提取的括号匹配器(
embedded_procsub_close,src/parser/process_substitution.rs;其字节孪生skip_procsub_paren,src/parser/token_actions.rs)对 backquote 组盲:组体内未配平的(直接计入深度,真闭合符永远配不平,整段跨度被漏认领;随后展开器把组体文本当作词层文本处理,连组体内的 backquote 都在外层被展开掉。组体内未配平的"以同机理腐蚀匹配器的引号状态,同样吞掉真闭合符。GNU 锚点
subst.c:1311extract_process_subst→xparse_dolparen(parse.y:4686):跨度体由真正的解析器重解析;parse.y:3877parse_matched_pair:嵌套替换单元(含 backquote 组)经 shellquote 臂整段当作单位消费。(是内层命令文本的数据,绝不是外层跨度的嵌套层级。修法
两个匹配器现都把 backquote 组整段跳过:字符版复用 PR #3351 已有的
backquote_group_end(转发 lexerskip_backtick_corrected);字节版新增其孪生skip_backtick_bytes(与skip_backtick_corrected同规则:反斜杠携带下一字节,首个其余 backquote 闭合)。两处门限均为!single(与本文件内同族扫描一致:backquote 组在双引号内仍有效);未闭合的组回落到原逐字行走。回归钉
tests/issue3354_procsub_backquote_paren.rs,6 格,期望以 GNU bash 5.3.20 实测为准:(skip_procsub_paren)"的引号状态面验证
scrubbed_cargo.py cargo test --locked --test issue3354_procsub_backquote_paren)。685ccbc4的 worktree)逐数对齐。RUSTFLAGS="-D warnings" cargo check --locked --lib --binsrc=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