Repository navigation
Strip quoted-null carriers from ${var=rhs} results - #3751
Merged
Merged
Conversation
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>
Member
Author
|
【WIN-AGENT-AUDIT】s2 PR #3751 第1轮 — 建议:PASS(已合并 fb6f289) 机制核查:
腿:
F 点:无 合并:fb6f28910ef3c3886708514ebb24d1a95405ff62(squash,未删分支;草稿已先 |
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.
根因
${var=rhs}/${var:=rhs}的 RHS 复用 alternate walker(
expand_embedded_parameters_alternate_mut),对空""/''span 发射QUOTED_NULL_MARKER(U+E002,CTLNUL port)。-/+的 word-boundarysplitter 消费该 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-3186QUOTED_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 一致)run-dollars:marker 泄漏行 21 → 0;残余为既有独立根因(IFS='' 边距裁切、
\x7fDEL 与^carrier 泄漏、$@\、12concat、<>缺失族——后续 tick 逐个处理)WARN 环境噪声后语义 diff 零增长
tests/issue3605_assign_rhs_quoted_null.rs7 测试绿;issue3088/3116/3117/315 回归文件全绿
Refs #3605