Skip to content

fix(executor): GNU UNQUOTED null-word discard for inner quoted nulls - #3748

Merged
caomengxuan666 merged 2 commits into
masterfrom
devin/dollar-at-quoting
Nov 16, 2026
Merged

caomengxuan666 merged 2 commits into
masterfrom
devin/dollar-at-quoting

Conversation

@caomengxuan666

Copy link
Copy Markdown
Member

Summary

run-dollars $*/$@ empty-word semantics: an UNQUOTED word whose expansion is all-null must be discarded even when the null was produced by quoted constructs INSIDE the word's own ${...}/$(...) (GNU subst.c:12026-12048 — the inner had_quoted_null does not set the outer word's quoting state).

Fixes recho ${v=''}, recho ${v= ''}, recho ${v=$*} (empty positional) emitting a spurious <> argument, plus "$@" segment scanning of backslash/literal pieces ("123 $@\ 456" family).

  • command_prepare.rs: strip bare QUOTED_NULL_MARKERs before the empty/split verdicts for unquoted outer words; widen the empty-expanded discard past the Variable-kind admission ([[ guard preserved)
  • command_words.rs: an empty expansion never field-splits
  • command_substitution_values.rs: backslash scanned per double-quote escape rules; literal pieces cooked via remove_double_quoted_into_cursor (now pub(crate))

Verified byte-identical to GNU bash 5.3.20 across the probe matrix and the dollar-*.sub slice; residual diffs are the pre-existing ${op+ RHS} inner-space family (separate root cause).

Refs #3605

…ulls (Refs #3605)

GNU subst.c:12026-12048 (expand_word_internal end-of-word): a word whose
expansion is all-null keeps one field only under had_quoted_null or
PARTIALLY_QUOTED state; an UNQUOTED word (or quoted_dollar_at) is
discarded. Quoting bytes inside the word's own ${...}/$(...) constructs
are inner syntax, so QUOTED_NULL_MARKERs produced by ${v=''} never
anchor the outer field.

- strip bare QUOTED_NULL_MARKERs from the expanded word before the
  empty/split verdicts when the word itself is unquoted (${v=''},
  ${v= ''}, ${v=$*} with an empty positional now drop; [[ operands
  and partially/fully quoted outer words are unchanged)
- widen the empty-expanded discard past removes_unquoted_null_word's
  TokenKind::Variable admission for the same UNQUOTED class
- splits_unquoted_expanded_word: an empty expansion never splits (the
  remove/keep decision already ran upstream)
- quoted "$@" segments: scan backslash per double-quote rules and cook
  literal pieces through remove_double_quoted_into_cursor (pub(crate)),
  so "123 $@\ 456"-family spans segment correctly

Verified: probe matrix (at3/at3b/at3c/at5b-h/at10-e, st10/st10b) and the
dollar-*.sub gate slice are byte-identical to GNU bash 5.3.20 except the
pre-existing ${op+ RHS} inner-space family (dollar-at-star9/dollar-star7/
dollar-star9/dollar-at7, separate root cause).

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
@caomengxuan666

Copy link
Copy Markdown
Member Author

队长复核:FAIL(E7 marker-lint,1 处违规,须返工)。

Linux Rust tests job 未跑到 lib 测试——死在 Check marker blind-consumer hygiene 步(run 43761562739,job 19s 速败即此故):

  • marker-lint: 1 violation(s)
  • src/executor/command_prepare.rs:3105: L3 .contains( keyed on registry const QUOTED_NULL_MARKER at an unreviewed site — route it through a pair-aware helper in markers.rs, or allowlist it with the invariant that makes it sound

本 PR 在 command_prepare.rs:3105 直接用 .contains(QUOTED_NULL_MARKER) 判裸 marker,属 blind-consumer 违规(同 #3700 在 compound_exec.rs:5423 的 E7 失败同族)。修法二选一:① 走 markers.rs 的 pair-aware helper;② 在 allowlist 登记该处,并写明使之 sound 的不变量。修后重跑 CI,Linux Rust tests job 的 lib 腿须重新证实。

其余腿已按名,无 PR 专属红:goldens job lib 腿 1351/1、macOS lib 1245/1,唯一红格皆 issue2875 基线;canary 只红已知 ledger 漂移(MISSING Session::cwd,repl.rs:2004)。正文缺「本 PR 删除了什么」节,合入时队长补。

…ware helper

E7 marker-lint flagged the bare .contains(QUOTED_NULL_MARKER) at the
unquoted-null-word boundary as an unreviewed blind-consumer site. The
check itself only routed into restore_bare_sentinels (already
pair-aware), so the fix is the offered shape: a Cow-returning
single-rule helper in markers.rs that keeps the no-marker borrow and
confines the needle operation to the registry module.

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
@caomengxuan666

Copy link
Copy Markdown
Member Author

E7 违规已修(新头 f477ff72):按选项 ① 走 pair-aware helper —— markers.rs 新增 restore_bare_sentinel_cow(单规则、无 marker 时借用不分配),command_prepare.rs:3105 的裸 .contains(QUOTED_NULL_MARKER) 移入注册表模块内部(该处本属 exempt)。check-marker-literals.py 本地 OK(117 consts / 268 sites),5 个 pin 测试全绿,fmt 净。Linux Rust tests job 的 lib 腿待 CI 重证。

@caomengxuan666

Copy link
Copy Markdown
Member Author

队长复核:FAIL 撤销,返工已核,入 Wave 2。

新头 f477ff72(refactor(markers),command_prepare.rs + markers.rs,+22/−7)按 FAIL 评论的选项 ① 走 pair-aware helper:markers.rs 新增 restore_bare_sentinel_cow(单规则、无 marker 时借用不分配;命中时进 pair-aware restore_bare_sentinels,注释写明 absence check 不会误读 E400 pair),command_prepare.rs 的门控改调该 helper,裸 .contains(QUOTED_NULL_MARKER) 已移入注册表模块内部。本地 marker-lint 117 consts / 268 sites OK(作者注记 6902971537)。

新头 CI 已按名(run 43773489867 / canary 43773489871):三条 lib 腿失败测试按名皆仅 api::consumer_tests::issue2875_input_procsub_child_runs_as_rubash_shell(goldens 1351/1、macOS 1245/1;Linux 腿此前死在 E7 步,这次已跑到 lib 测试,marker census 诸测皆绿);canary 只红已知 ledger 漂移(MISSING Session::cwd)。未引入新红。

Wave 2 仍欠:钉 fail-first + 全绿、邻居、lib 双边、RUSTFLAGS="-D warnings"、守卫扫描。正文仍缺「本 PR 删除了什么」节,合入时队长补。

@caomengxuan666

Copy link
Copy Markdown
Member Author

【WIN-AGENT-AUDIT】PR #3748 第2轮 — 建议:PASS
head: f477ff7 base(merge-base): 0a405d8 文件: 6 个 +250/-22
关联 issue: #3605(状态:open,伞目录 issue,按台账铁律不关单;我核过的时间:2026-11-16 本地)

机制核查:

  • 机制成立。GNU expand_word_internal 的收尾判定(subst.c:12026-12048)只看外层词的 quoted_state:had_quoted_null || (quoted_dollar_at == 0 && quoted_state == PARTIALLY_QUOTED) 才保留一个空 field;外层 UNQUOTED 或带引号 "$@" 一律丢弃。${v=''}/${v=$*} 里的引号属于内层参数展开,只标内层 had_quoted_null(subst.c:11744-11749),不会把外层词变成 PARTIALLY_QUOTED——本 PR 的 raw_word_is_partially_quoted(src/executor/command_prepare.rs:5114-5153)正是按这条边界分类:跳过 ${...}/$(...)/`...` 内部再判外层引号。"123 $@\ 456" 族对应 parse.y 双引号内反斜杠只转义 $ " \ `` `` \n的规则(command_substitution_values.rs:2035-2045 的'\' => match body.get(index+1)`)。
  • 无无关改动:6 个文件都在同一条链上(prepare / words / comsub-values / markers helper / lexer 可见性 / 新钉),restore_bare_sentinel_cow 是队长上轮 E7 违规的整改(裸 .contains(QUOTED_NULL_MARKER) 收进注册表模块),无桥接/翻译层,未碰 src/lexer/continuation.rs,无新公开面(remove_double_quoted_into_cursor 仅 pub(crate))。

腿(逐项给数字与名字):

  • 钉自跑 issue3605_unquoted_inner_quoted_null:5 passed / 0 failed。
  • fail-first:base(0a405d8 src) 上 3 passed / 2 failed,红名 = {issue3605::unquoted_brace_alternate_quoted_null_drops, inner_null_marker_leaves_literal_text}。其余 3 格(${v=$*} 空位、quoted/partial 外层、[[ 操作数)在 base 上即绿——它们是「不变对照」格;其中 ${v=$*} 格正文声称修的是「多余 <> 参数」,但 base 上该形状实测已与 GNU 一致(set -- ''; set -- ${v=$*} → 0 参),故该格在本 base 上非判别钉(不构成回归风险,仅无事前红证据),已在本报告记录,不作 FAIL。
  • lib 双边:head 失败名集 {api::consumer_tests::issue2084_session_end_restores_host_process_state} / base(0a405d8,本轮 target/lib3749-base.log) 失败名集 {同} / 差集 {}。
  • -D warnings:cargo check --locked --lib --bins clean,0 警告。
  • 卫生:rustfmt --check 7 文件 clean;marker-lint OK (117 registry consts, 268 allowlisted sites)(上轮 E7 违规已消失);utf8-hygiene clean。
  • CI:红 4 个——Rust tests(仅 issue2875,且 marker-lint 步已 OK)、Rust tests (macOS)(issue2875,1245 passed/1 failed)、GNU regression goldens and canaries(issue2875,1351 passed/1 failed)、niubash builds(Session::cwd API ledger 缺口,跨仓漂移基线,与 fix(executor): net bind saves displaced fd via kernel dup (Refs #3726) #3740 轮记录同因)。均非本 PR 引入。
  • GNU 对照(WSL /usr/local/bin/bash 5.3.20(1)-release,脚本文件形;探针 target/probe/m3605.sh、m3605b.sh、n1b.sh):32 个形状里 31 个逐字节相同,含 ${v=''}/${v= ''}/${v=$*}(0/1/2 个空位)、"${v=''}"、''${v=''}、x${v=''}y、"$(true)$@" vs "$(true)""$@"、"''$@"、"x$@y"、"123 $@\ 456"、"$*$x"、${v=''}$((0))、"$@"$x 等。唯一残差:set -- "${v=''}"$x(x 未设)GNU 输出 1 参内容 '',head/base 均为 1 参空串——base 上同值,属既存相邻面(双引号内 ${v=word} 的 word 逐字保留 '' 这条规则与后续未加引号空展开的组合),不在本单修复面。

F 点:无

未跑/VOID 的腿:无

合并处置:head 与审计时点一致(f477ff72)、MERGEABLE,已 squash 合入;#3605 为伞目录 issue,按台账铁律不关单。

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