Skip to content

Decode $"..." locale strings in embedded-parameter walkers and quoted operator words (Refs #3086) - #3258

Merged
caomengxuan666 merged 2 commits into
masterfrom
fix/3086-dollar-quote-walker
Nov 10, 2026
Merged

caomengxuan666 merged 2 commits into
masterfrom
fix/3086-dollar-quote-walker

Conversation

@caomengxuan666

Copy link
Copy Markdown
Member

概要

Refs #3086

$"..." 在 C 语言环境下与 "..." 完全等价(GNU subst.c:4133 expand_string_dollar_quote 的 $" 臂;subst.c:1639 sh_mkdoublequoted),但 rubash 有三处扫描面没有 $" 臂。本 PR 按机制补齐三处,而不是按 $((...)) / ${...} 等形状逐个打补丁:

  1. 共享嵌入参数 walker(&self 与 &mut 两份扫描实现):$ 后跟 " 原落入兜底臂被逐字输出,$(( $"1+2" )) 报操作数错误、${q-$"a b"} 的默认词被误读。
  2. 引号上下文算子词的提取期解码器 decode_double_quotes_in_quoted_parameter_word:它有 $' 臂(提取期 ansiexpand)却无 $" 臂——$"a b" 的引号被当普通双引号句剥掉、孤儿 $ 喂给展开 walker 后把 span 首词当参数名展开(${q-$"a b"} 在双引号上下文里得到 b,$"ab" 整体消失)。

修法

  • src/executor/embedded_parameters.rs(&self walker,expand_embedded_parameters_inner 的 $ 分发):新增 Some('"') 臂,守卫 !heredoc && !in_double && !double_quoted。触发时消费 "、置 in_double、preserve_quotes 模式保留引号形——与该 walker 既有的裸 " 臂完全同规,span 内容与闭引号由同一主循环按双引号语义续扫(展开、IFS 保护、引号移除皆复用既有纪律)。
  • src/executor/embedded_mutations.rs(&mut walker,expand_embedded_parameters_ordered_mut 的 $ 分发):同样的臂,守卫另加 context == Unquoted,并同步该 walker 裸 " 臂的 alternate 模式引号空值记账(dquote_open_len)。${...} 的赋值形(如 := 默认词)经此 walker,故两面都必须补。
  • src/executor/parameter_words.rs(decode_double_quotes_in_quoted_parameter_word):在裸 " 句解码前消费 $" 的 $ sigil,让 span 走既有双引号句解码(转义、嵌套单元皆复用)。GNU 依据:提取期 reader 把 $"..." 先 locale_expand 再以 sh_mkdoublequoted 重裹成真双引号 span(parse.y:5546-5610 read_token_word,重裹在 parse.y:5582-5595;${...} 提取扫描同源,parse.y:4095-4126),词到达展开期时本就是一个双引号 span。heredoc 时不触发——GNU 的 heredoc 扫描在 ${...} 词内同样不做 locale 解码(与同函数 $' 臂同门控,实测 [ b] 形双边一致)。
  • 守卫依据(GNU bash 5.3.20 实测):已在双引号 span 内时 $ 是字面数据("a$"b"c" → a$bc),heredoc 内 $"x" 逐字保持——这些形态不触发新臂、保持原逐字路径。

钉与验证

  • 回归钉 tests/issue3086_dollar_locale_quote_walker.rs(12 格)已随 PR test: wave-2 pins E3 (Refs #2713 #2752 #3085 #3086) #3164 入 master,本 PR 不动钉。基底 fail-first 三度复现:2 绿 / 10 红(绿 = D7 词法层控制、D12 $' 对照;红 = D1–D6、D8–D11)。
  • 头钉 12/12 全绿;邻茎 9 茎全绿(issue3085/2713/2752/3024/3023/2210/2217/3071/2343);lib 双边 rc=0、失败名集双边为空且恒等;RUSTFLAGS="-D warnings" rc=0;cargo fmt --check rc=0;python3 scripts/check-marker-literals.py OK。
  • GNU 差分扫 21 探针:19 same;余 2(p09/p09b,${q:?...} 错误词)为先存残差——:? 诊断路径对一切双引号 span 都漏 IFS_GLUE 载体(基底对普通 "e f" 同样漏 \x1c,base/head 逐字相同),与本单无关;$" 内容本身在该面已由不解码(基底输出 $" e f")改为正确解码。详见车道 REPORT。
  • 验证环境说明:本机写墙与单槽队列长期阻塞,完整腿在 Simular box(master e1afd25d 树,三目标文件与本 PR 基底逐字相同)上以同口径跑齐;本机槽内另有一轮独立确认(基底 2/10、九邻茎全绿、lib/warnings/fmt 全绿,该轮头钉 8/12 即引出上面第 2 面的定位与修复)。

本 PR 删除了什么

无文件删除、无功能移除。产品代码净 +63/−0:三处扫描面各新增一个 $" 分发/解码臂,未删除或替换任何既有实现行。

… the quoted operator-word decoder

Refs #3086

GNU treats $"..." as a locale string that its extraction-time reader
locale-expands and re-wraps as a genuine double-quoted span before any
expansion scan sees it (parse.y:5546-5610 read_token_word, sh_mkdoublequoted
re-wrap at parse.y:5582-5595; the ${...} extraction scan rides the same
reader, parse.y:4095-4126; expansion-time form at subst.c:4133
expand_string_dollar_quote and subst.c:1639). Three rubash scan faces had
no $" arm:

- expand_embedded_parameters_inner (&self walker): $ fell through
  verbatim, so $"..." inside $((...)) bodies and ${...} operator words
  was never decoded as a quoted span.
- expand_embedded_parameters_ordered_mut (&mut walker): twin gap on the
  assignment-shaped operator-word route (:= words).
- decode_double_quotes_in_quoted_parameter_word: had a $' arm
  (extraction-time ansiexpand) but no $" arm, so the span's quote was
  stripped as a plain sentence opener and the orphaned $ reached the
  walker, which expanded the span's first word as a parameter name
  (${q-$"a b"} in a double-quoted context yielded " b").

Each face gains the missing arm at the mechanism level: the walkers open
a double-quoted span exactly like their bare-quote arms (same guards:
not in heredocs, not inside an open span, not in quoted contexts), and
the decoder consumes the $ sigil and lets the existing double-quote
sentence decode process the span. Heredoc ${...} words stay raw, which
matches GNU's here-document scan.

Verification (pin tests/issue3086_dollar_locale_quote_walker.rs, already
in master via PR #3164): base 2 passed / 10 failed, head 12 / 12;
9 neighbour stems green; lib bilateral rc=0 with identical empty failure
name sets; RUSTFLAGS="-D warnings" rc=0; cargo fmt --check rc=0;
check-marker-literals OK.
@caomengxuan666
caomengxuan666 merged commit 8f4daa2 into master Nov 10, 2026
11 checks passed
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