Repository navigation
Decode $"..." locale strings in embedded-parameter walkers and quoted operator words (Refs #3086) - #3258
Merged
Conversation
… 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
marked this pull request as ready for review
November 10, 2026 12:53
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.
概要
Refs #3086
$"..."在 C 语言环境下与"..."完全等价(GNU subst.c:4133expand_string_dollar_quote的$"臂;subst.c:1639sh_mkdoublequoted),但 rubash 有三处扫描面没有$"臂。本 PR 按机制补齐三处,而不是按$((...))/${...}等形状逐个打补丁:&self与&mut两份扫描实现):$后跟"原落入兜底臂被逐字输出,$(( $"1+2" ))报操作数错误、${q-$"a b"}的默认词被误读。decode_double_quotes_in_quoted_parameter_word:它有$'臂(提取期 ansiexpand)却无$"臂——$"a b"的引号被当普通双引号句剥掉、孤儿$喂给展开 walker 后把 span 首词当参数名展开(${q-$"a b"}在双引号上下文里得到b,$"ab"整体消失)。修法
src/executor/embedded_parameters.rs(&selfwalker,expand_embedded_parameters_inner的$分发):新增Some('"')臂,守卫!heredoc && !in_double && !double_quoted。触发时消费"、置in_double、preserve_quotes 模式保留引号形——与该 walker 既有的裸"臂完全同规,span 内容与闭引号由同一主循环按双引号语义续扫(展开、IFS 保护、引号移除皆复用既有纪律)。src/executor/embedded_mutations.rs(&mutwalker,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-5610read_token_word,重裹在 parse.y:5582-5595;${...}提取扫描同源,parse.y:4095-4126),词到达展开期时本就是一个双引号 span。heredoc时不触发——GNU 的 heredoc 扫描在${...}词内同样不做 locale 解码(与同函数$'臂同门控,实测[ b]形双边一致)。$是字面数据("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)。RUSTFLAGS="-D warnings"rc=0;cargo fmt --checkrc=0;python3 scripts/check-marker-literals.pyOK。${q:?...}错误词)为先存残差——:?诊断路径对一切双引号 span 都漏 IFS_GLUE 载体(基底对普通"e f"同样漏\x1c,base/head 逐字相同),与本单无关;$"内容本身在该面已由不解码(基底输出$" e f")改为正确解码。详见车道 REPORT。e1afd25d树,三目标文件与本 PR 基底逐字相同)上以同口径跑齐;本机槽内另有一轮独立确认(基底 2/10、九邻茎全绿、lib/warnings/fmt 全绿,该轮头钉 8/12 即引出上面第 2 面的定位与修复)。本 PR 删除了什么
无文件删除、无功能移除。产品代码净 +63/−0:三处扫描面各新增一个
$"分发/解码臂,未删除或替换任何既有实现行。