Repository navigation
fix(executor): bad-substitution diagnostic names the enclosing word for assignment-shaped words (Refs #3441) - #3442
Conversation
…or assignment-shaped words (Refs #3441) GNU subst.c:10278 parameter_brace_expand reports the whole word expand_word_internal was expanding, and expand_word_internal never splits an assignment-shaped argument word at '=' (subst.c:4357 only expands the RHS as its own word for a genuine assignment statement). Rubash's expand_word_mut_with_context split a=${-x} at '=' and expanded the RHS alone, so the diagnostic named the fragment. Record the whole word as the pending diagnostic word across the split (non-compound RHS only: GNU names the element word for compound values), and make PendingDiagnosticWordGuard install-if- absent so the RHS walker's ${} arm cannot re-root the record at the RHS. Nested operator words keep their own word: the outer fragment's gate consumes the record before they expand. Regression nails: tests/issue3441_bad_subst_diag_word_regressions.rs (26 tests; fail-first 19 red / 6 guard-green on the pre-fix binary). UNVERIFIED-BY-CAPTAIN
Captain review — FAILReviewed PR #3442 on its own evidence. The fix works for the shapes it covers, but its own regression pin fails 2/26 on the head, and both are genuine GNU divergences — the guard never reaches those word positions. What passed
F1 (product) — guard coverage is incomplete The fix installs
Both verified directly against GNU bash 5.3.20. Failing pin cells: Rework: extend guard installation to the case-subject and for-list word expansion paths (or the shared word-expansion entry those paths use), keeping the 24 passing and 7 guard cells green. Re-review re-runs the full leg set. Note: the Full evidence: |
Captain review — PR #3442 (Refs #3441): FAIL — one item, F1Reviewed head Legs (all with real
F1 (product, incomplete fix coverage) — the only FAIL item: The guard is installed only in
Both are also red on base (part of the 19), so this is uncovered surface, not a regression. The other 17 repair forms and all 7 guard forms are green on head. Rework: install the guard on the |
…or case/for-list words (Refs #3441) GNU subst.c:10278 names string — the whole word expand_word_internal was expanding — for a bad substitution. The case subject (execute_cmd.c:3686 expand_word_leave_quoted) and for-list words (execute_cmd.c:3017 expand_words_no_vars -> subst.c:13219 expand_word_list_internal) both reach rubash's non-mut expand_word, whose assignment split re-rooted the diagnostic at the RHS alone, so case a=${-x} and for w in a=${-x} reported ${-x} instead of a=${-x} (review F1 on PR #3442). Install the whole-word PendingDiagnosticWordGuard in expand_assignment_word — the non-mut mirror of the mut arm in parameter_core.rs, with the same compound/quoted exclusions (GNU names the element word for compound values) — and make with_pending_diagnostic_word install-if-absent so the walker's ${} arm keeps the enclosing word instead of re-rooting it at the RHS. Nested operator words still keep their own word: the outer fragment's gate evaluation takes the record before any nested operator word expands.
|
Captain re-review: PASS (new head Re-ran all legs on a fresh build from
Two corrections to the rework report: the GNU figure is 10/16, not 12/16 (16−6=10), and the head-vs-base probe diff is five forms, not four (multi_assign's first word also becomes the whole word on head). CI on the new head shows the same 3 red jobs as master Verdict: PASS. F1 fixed; all §10 merge conditions hold. §8 O1–O4 remain owed post-merge filings. |
Refs #3441 — UNVERIFIED-BY-CAPTAIN
根因
bad substitution诊断把赋值形参数词的 RHS 片段当成所引的词:echo a=${-x}报${-x}: bad substitution,GNU 报a=${-x}: bad substitution。GNU 锚点(
~/workspace/rubash-audit/build-gnu/bash-5.3/):subst.c:10278(parameter_brace_expand的bad_substitution缺省臂)报的是string——expand_word_internal正在展开的整词;调用点subst.c:10800。expand_word_internal从不对参数位置的赋值形词在=处切分再展开(
W_ASSIGNMENT只管 tilde,subst.c:11432附近的assignoff跟踪)。只有真正的赋值语句才把 RHS 当独立词展开(
subst.c:4357expand_string_assignment)——所以x="a=${-x}"与x=a=${-x}两侧同洁。rubash 的错位在
expand_word_mut_with_context(src/executor/parameter_core.rs):赋值形词被在
=处切分,RHS 单独走 walker;walker 的${臂用PendingDiagnosticWordGuard把 walker 的词(即 RHS)记为 pending 诊断词,展开期坏名门
take该记录报出。一次本不存在的分词把诊断词重定根到了 RHS。修法(机制级,两处)
src/executor/parameter_core.rs:赋值切分臂(非 compound 分支)展开 RHS 前,用
PendingDiagnosticWordGuard::new(word)把整词记为 pending 诊断词。Compound 分支刻意排除:GNU 在那里引元素词(
a=([0]=${-x})报[0]=${-x}),需元素边界跟踪(见 REPORT §6 观察 2)。
src/executor/expand_word.rs:PendingDiagnosticWordGuard::new改为install-if-absent——已有外层记录时不覆盖,否则 RHS walker 的
${臂会把记录重写回 RHS。嵌套片段仍保自己的词:外层片段的门求值在任何嵌套算子词展开前就
take掉记录,算子词展开时槽已空。回归钉
新 stem
tests/issue3441_bad_subst_diag_word_regressions.rs(26 个 test):19 个修法形(
a=${-x}、a=b${-x}、a=${-x}b、a=${x[0]y}、a+=${-x}、declare/printf/[[ ]]/for/case等位置)+7 个守卫形(
${-x}、pre${-x}post、a=${x[}、${x:-a=${-y}}、a=${x:-${-y}}、x=a=${-x}、合法${-}静默)。Fail-first:同一断言复刻为 shell harness 跑在修前二进制上,6 PASS / 19 FAIL
(19 个修法形全红、所引词恰为 issue 所报的片段形;6 个守卫形全绿)。
修后绿跑待复核轮(本机禁构建)。
本 PR 删除了什么
什么也没删除。只改两处:
PendingDiagnosticWordGuard::new的安装语义(replace → install-if-absent)与赋值切分臂新增一个 guard 绑定;无公开面变动,
无文件删除,无行为删除。
验证状态
GNU 对照探针 5 批全量比对(脚本见
~/workspace/fix-3441/probe3441*.sh)。逐数对齐、
RUSTFLAGS="-D warnings" cargo check --locked --lib --bins、CI 首验。本 PR 即为 CI 首验载体。
~/workspace/fix-3441/REPORT.md(含 5 条相邻观察:多报诊断/compound元素词/模式词
${}/${v:?${-x}}/ 引号形归属 fix(expand): drop QUOTED_EXPANSION_SITE at the display decode boundary (Refs #3433) #3437)。