Repository navigation
parser: backquote groups are opaque to the raw procsub word scans (Refs #3337) - #3351
Conversation
Eight cells mirroring the issue3221 pin harness (single-process scripts, outer exec 3>tap.log): the backquote assignment shape, the group embedded in a larger word, the group inside double quotes, the group in an argument word, an input procsub inside the body, the consumer fd-3 target readback (linux), and two guards (escaped backquote, plain top-level embedded procsub). Expectations measured on GNU bash 5.3.20 with the lane probe matrix (10/10). Refs #3337
The three raw word scans in process_substitution.rs (embedded extraction, has-unquoted admission, verbatim span location) skip dollar-introduced groups whole (dollar_group_end) but walked straight through backquote groups, so a process substitution inside a backquoted command substitution was claimed by the outer word: the consumer materialized at the outer level, where an exec 3<&1 inside the body has not rebound fd 3 and the fd resolves to the ambient context instead of the capture pipe. GNU expand_word_internal consumes a backquote unit whole in its own arm (subst.c:11572 case backquote: string_extract pulls the span, command_substitute (subst.c:7143) executes the body), so an angle bracket inside one never reaches the process substitution arms (subst.c:11364-11378) at this word level. Mirror that invariant with a backquote_group_end helper reusing the lexer backquote walker (skip_backtick_corrected) and a skip arm beside each dollar arm. The backquote arm is not suppressed inside double quotes (only the angle arms are), so the skip gates on not-single only. Refs #3337
The echo-argument form of the top-level embedded guard hits a separate pre-existing face (builtin argument words execute a mid-word procsub body but do not splice the fd path; identical on base and head, delimited with probe-embedded-forms.sh and probe-faceA-delimit.sh in the lane probes). The assignment form asserts the same scan claim through the synchronous value readback and is deterministic on both trees. Refs #3337
|
复核员在 Simular box 独立复跑(树内现建二进制、干净 fd 上下文),申报逐项对账全合: 钉双边(茎名 ls 实查)
探针矩阵(车道 probe-bq-matrix.sh 同文件三方,sha256 已核)
其余腿
GNU 锚点亲核:subst.c:11572 backquote 臂以 附带定界(#3353 / #3354):均不被本 PR 覆盖。 复核探针在 base/head/现尖三树隔离实测:#3353 的内建中段跨度形三树同形(组体执行、拼接丢失,外部/赋值路线正常);#3354 的赋值形三树同形(跨度漏认领、cap 为空),词首对照形三树与 GNU 全同。两单维持独立修法面,合入后仍 OPEN。附注:#3354 的匹配器缺的正是 backquote 跳过臂,本 PR 的 一处复核侧记录:中段曾以树里现成的旧 合入轮按卷宗 §9 执行:活尖重算交集 → update-branch → 合并头同轮现建二进制重跑钉/邻茎/lib/探针 → 全靶警告按现尖 rc=0 全清口径 → 最终头 CI finished 全绿 → 以既备 merge-body squash(唯一 closing 共现 |
…efs #3354) (#3431) ## 根因 嵌入式进程替换跨度提取的括号匹配器(`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 | 组内未配平 `"` 的引号状态面 | 红 | 绿 | ## 验证(队长复核亲跑,见 `~/workspace/review-3431/CAPTAIN-VERIFY.md`) - 新钉:基底顶补 3/6(红恰 01/03/06)、本头 6/6,逐名核对。 - 全量 lib 双边:本头 1246 passed / 0 failed / 4 ignored,与基底逐数对齐,失败名集双边皆空。 - 三方探针(GNU 5.3.20 / 基底 / 本头):复现、矩阵、引号三脚本,本头与 GNU 逐字一致(仅 /dev/fd 数字随分配顺序浮动);基底在 issue 形与复合赋值面分歧如 issue 所述。 - 邻茎:issue3337 8/8、issue339_340 10/10、issue1561 9/9、issue1523 6/6、issue1690 1/1。 - `RUSTFLAGS="-D warnings" cargo check --locked --all-targets`:rc=0,1479 次 rustc 调用,0 警告、0 错误。 - rustfmt、marker-lint、UTF-8 边界卫生全绿;CI 11 腿全绿(含 goldens 与双 cross-target)。注:CI 的 nextest 精选表不含新钉 stem(见 #3430),钉面以复核员亲跑为准。 ## 本 PR 删除了什么 无。纯加法修法:两处匹配器各加一个 backquote 跳过臂(+59 行产品代码),新增一个 6 格回归钉文件。未删任何函数、分支、测试或公开面;未改 `docs/api-ledger.md`;未碰 `src/lexer/continuation.rs`。 Fixes #3354
概要
命令替换的 backquote 形态下,组内的进程替换被外层词的 raw 扫描误认领:赋值材料化在外层先把组内的
>(...)生成出来,消费者在外层上下文运行——此时 backquote 本体内exec 3<&1的 fd 3 重绑定尚未发生,fd 3 是环境 fd(外层exec 3>tap.log的 TAP 文件),hello 落进日志而非 comsub 捕获管道。$(...)同形已由 #3221 一线处理:parser 的三处 raw 词扫描(embedded 提取、has-unquoted 判定、verbatim 跨度定位,src/parser/process_substitution.rs)在 #3132 时补上了「$引入的成组跨度不透明」(dollar_group_end,复用 lexer 的dollar_word_group_len)。backquote 组不在其列。本 PR 给同一组扫描补上 backquote 跨度的不透明臂(backquote_group_end,复用 lexer 的skip_backtick_corrected,与 tokenizer 同一 walker),谓词口径按 GNU 分工分开:expand_word_internal(subst.c)在 backquote 臂(subst.c:11572case '')以string_extract整段取走组体、交command_substitute(subst.c:7143)作为内层命令文本执行;组内的</>` 永远到不了本词层面的进程替换臂(subst.c:11364-11378)。</>臂被Q_DOUBLE_QUOTES抑制,backquote 臂不被抑制),故跳过臂只以!single为门,不以!double为门——同时避免组体里的"污染扫描的引号状态。按机制修:凡 backquote 组出现在词扫描路径上(赋值 RHS、参数词、组内嵌组、双引号内组),组内跨度一律归内层命令文本自身,不按复现字符串特判。
本 PR 删除了什么
无删除。三处 raw 扫描各补一个与既有
$臂同形的 backquote 跳过臂,并新增一个内部助手函数;钉文件为新增。回归钉
tests/issue3337_backquote_procsub_opacity.rs(8 格,镜像 issue3221 钉的单进程 harness):exec 3<&1+>(cat >&3)(立案原形)<(...)>(...)仍是本词的真进程替换期望全部以 GNU bash 5.3.20 实测锁定(车道探针矩阵 probe-bq-matrix.sh,GNU 侧 10/10)。
验证
全部腿在 Simular box 跑(树
~/work/fix-3337,日志~/work/f3337-logs{,2}/),基底 = masterdb0c1a40,头 = 本 PR 头:probe-bq-matrix.sh,10 格,脚本文件形态):GNU 5.3.20 侧 10/10;基底红恰三格(bq-out 测得 1/1、bq-fd3-type 消费者 fd 3 为日志文件路径、bq-pre-suffix 测得 prehellopost//1),其余七格(含$()对照、转义 backquote 守卫、算术对照)基底全绿;头 10/10。OUT:[hello] TAP:[hello|]);03/04/05 三个同族锁格与 07/08 两个守卫格基底全绿。头钉 8 过 / 0 败。test result行、全绿。RUSTFLAGS="-D warnings"(--lib --bins)rc=0;marker-lint OK;UTF-8 boundary hygiene clean;cargo fmt --checkrc=0。定界中另发现两条姊妹残差(基底与本头同形、非本 PR 引入,已立案):#3353(内建参数词的中段跨度不拼接 /dev/fd)、#3354(跨度提取括号匹配对 backquote 组盲)。
Refs #3337