Skip to content

Strip quoted-null carriers from ${var=rhs} results - #3751

Merged
caomengxuan666 merged 1 commit into
masterfrom
devin/dollar-rhs-qnull
Nov 16, 2026
Merged

caomengxuan666 merged 1 commit into
masterfrom
devin/dollar-rhs-qnull

Conversation

@caomengxuan666

Copy link
Copy Markdown
Member

根因

${var=rhs}/${var:=rhs} 的 RHS 复用 alternate walker
(expand_embedded_parameters_alternate_mut),对空 ""/'' span 发射
QUOTED_NULL_MARKER(U+E002,CTLNUL port)。-/+ 的 word-boundary
splitter 消费该 marker 锚定空字段;= 路径没有消费者,于是
recho ${v= "$x" }(x='')产出一个本不该存在的空参,run-dollars 泄漏
原始 U+E002 字节 21 行(dollar-at-star9.sub 的 ${v= "$*" } 族)。

GNU spec

  • subst.c:11843 / subst.c:11905:CTLNUL 只在
    (W_NOSPLIT|W_EXPANDRHS|W_ASSIGNRHS) == W_EXPANDRHS 时发射;=
    的 word flags 带 W_ASSIGNRHS(subst.c:4495),gate 失败,空
    ""/'' span 落 NOSPLIT2 丢弃分支(subst.c:11853、subst.c:11921)。
  • 嵌套 ${x- ""} 拼入的 quoted null 死于 list_string 的
    remove_quoted_nulls(subst.c:3181-3192)。
  • subst.c:8085:t1 = temp ? dequote_string(temp) : savestring("")
    —— = 结果在 bind_variable 与代入前 dequote。
  • 对照:subst.c:8080-8083 的 -/+ 原样返回 temp,CTLNUL 保留
    → 锚定空字段(subst.c:3181-3186 QUOTED_NULL branch)。

净效应:=/:= 的赋值值与代入文本均无 CTLNUL。"$x"(x='')
展开为 → field-split → 零参数;而 -/+ 保留一个 <>。

修法

expand_assignment_alternate_mut 对 RHS 结果做
restore_bare_sentinels(&[(QUOTED_NULL_MARKER, "")]) —— 与
non-alternate walker 边界已有契约一致(embedded_mutations.rs:
"every other consumer drops them like GNU's dequote_list")。
E400-aware:手打 $'' 仍是用户数据(rubash#2882)。

本 PR 删除了什么

无删除——=/:= RHS 结果新增一处 bare-marker 剥除(两个算子分支
共用 wrapper,单点覆盖 unquoted/double-quoted 两臂)。

验证(GNU Bash 5.3.20,script-file 探针逐字节)

  • ${v= "$x" }/${v= "$*" }/${v= "$@" }/${v= '' }/${v:= "$x" }/
    ${v= } → 零参数(此前 <>),v 正确赋
  • "${v= "$x" }" → < >;${v= a"$x"b } → <ab>
  • 嵌套 ${v= ${x2- ""} } → 零参数 + v=< >(GNU 一致)
  • IFS=''; set -- '' ''; ${v= "$*" } → < >
  • 对照 ${v- "$x" }/${v- "" }/${v+ "$x" } 仍锚定 <>(未过冲)
  • 手打 $'' 在 = RHS 原样进入 argv 与 v(od 一致)
  • gate run-dollars:marker 泄漏行 21 → 0;残余为既有独立根因
    (IFS='' 边距裁切、\x7f DEL 与 ^ carrier 泄漏、$@\ 、
    12 concat、<> 缺失族——后续 tick 逐个处理)
  • 相邻 suite(rhs-exp/more-exp/ifs/quotearray/posixexp2/new-exp)剥
    WARN 环境噪声后语义 diff 零增长
  • marker-lint OK(restore_bare_sentinels 为既有 sanctioned helper)
  • 新 pin tests/issue3605_assign_rhs_quoted_null.rs 7 测试绿;
    issue3088/3116/3117/315 回归文件全绿

Refs #3605

The `=`/`:=` rhs result is CTLNUL-free in GNU bash: CTLNUL is emitted
only when (W_NOSPLIT|W_EXPANDRHS|W_ASSIGNRHS) == W_EXPANDRHS
(subst.c:11843, subst.c:11905), and the `=` word flags include
W_ASSIGNRHS (subst.c:4495), so the gate fails and an empty ""/'' span is
discarded by the NOSPLIT2 branch (subst.c:11853, subst.c:11921). A
quoted null spliced in from a nested ${x- ""} dies in list_string's
remove_quoted_nulls (subst.c:3181-3192), then dequote_string runs on the
remainder (subst.c:8085). Contrast: `-`/`+` return the rhs raw with
CTLNUL intact (subst.c:8080-8083), anchoring an empty field through
word splitting (subst.c:3181-3186).

rubash's `=` rhs reuses the alternate walker
(expand_embedded_parameters_alternate_mut), which emits
QUOTED_NULL_MARKER for empty ""/'' spans. The `-`/`+` word-boundary
splitter consumes the marker; the `=` path had no consumer, so
`recho ${v= "$x" }` (x='') produced one empty arg where GNU produces
zero words. run-dollars.sub leaked the raw U+E002 byte in 21 diff
lines (dollar-at-star9.sub ${v= "$*" } family).

expand_assignment_alternate_mut now restores bare QUOTED_NULL markers
from the rhs result — the same contract the non-alternate walker's own
boundary already applies (embedded_mutations.rs, "every other consumer
drops them like GNU's dequote_list"). E400-aware: a typed $''
stays user data (rubash#2882).

Verified against GNU Bash 5.3.20 (script-file probes): unquoted and
quoted contexts, `:=` form, nested ${x- ""}/${x+ ""}, a"$x"b
concatenation, whitespace-only rhs, IFS='' $* join, and the
`-`/`+` anchor control cases all match byte-for-byte. Gate
run-dollars marker-leak family: 21 diff lines -> 0. New pin suite
tests/issue3605_assign_rhs_quoted_null.rs (7 tests); marker-lint,
issue3088/3116/3117/315 regression files green.

Refs #3605

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
@caomengxuan666
caomengxuan666 marked this pull request as ready for review November 16, 2026 11:05
@caomengxuan666
caomengxuan666 merged commit fb6f289 into master Nov 16, 2026
7 of 11 checks passed
@caomengxuan666

Copy link
Copy Markdown
Member Author

【WIN-AGENT-AUDIT】s2

PR #3751 第1轮 — 建议:PASS(已合并 fb6f289)
head: f092372;base(merge-base): 0a405d8;文件 2 个 +200/-1
关联 issue: #3605(伞目录 issue,保持 OPEN,未关)

机制核查:

  • GNU 只在 (W_NOSPLIT|W_EXPANDRHS|W_ASSIGNRHS) == W_EXPANDRHS 时发射 CTLNUL(subst.c:11843、subst.c:11905);=/:= 的 rhs word flags 含 W_ASSIGNRHS(subst.c:4495),gate 不成立,空 ""/'' span 走 NOSPLIT2 丢弃(subst.c:11853、subst.c:11921);嵌套 quoted null 由 list_string 的 remove_quoted_nulls 去掉(subst.c:3181-3192),再用 dequote_string(subst.c:8085)。净效果 = =/:= 的赋值值与代入文本都不含 CTLNUL。本 PR 在 expand_assignment_alternate_mut 对结果做 restore_bare_sentinels(QUOTED_NULL_MARKER → ""),与 non-alternate walker 已有契约一致(embedded_mutations.rs 注释),不是新机制;E400-aware 保留手打 $'\uE002' 用户数据。
  • 无删除、无无关面改动。

腿:

  • 钉自跑:issue3605_assign_rhs_quoted_null 7/7 pass(head)。
  • fail-first:base 0a405d8 同文件 4 passed / 3 failed,红名 = {assign_rhs_quoted_empty_spans_split_to_zero_words, assign_rhs_value_is_whitespace_only, nested_alternate_quoted_null_dies_in_assign_rhs}。
  • lib 双边:head {issue2084_session_end_restores_host_process_state} / base(0a405d8,本 lane 同法跑) 同集合 → 差集 ∅。
  • -D warnings:bin+lib 与 PR stem 0 警告;全仓 --tests 的 issue1794/2278 dead-code 为基线。
  • 卫生:rustfmt 两文件 0 差异;marker-lint OK;utf8 clean。
  • CI(run 43776874906):Rust tests = issue2875;macOS 1245/1 = issue2875;GNU goldens 1351/1 = issue2875;niubash = MISSING Session::cwd(ci: unmask master-red — issue2875 out/ resolver + masked test/corpus fixes #3750 面);其余绿。无 PR 专属红。
  • GNU 对照(WSL GNU bash 5.3.20(1)):11 形状 ${v= "$x" } / ${v= "$*" } / "${v= "$x" }" / ${v= a"$x"b } / ${v:= "$x" } / ${v= '' } / ${v= } / IFS=''; ${v= "$*" } / 对照 ${v- ...}、${v+ ...},含赋值后 v=[...] 的空白值,stdout 与 rubash 逐字节一致。探针 target/s2/probes/qn3751.sh。

F 点:无

合并:fb6f28910ef3c3886708514ebb24d1a95405ff62(squash,未删分支;草稿已先 gh pr ready)

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