Repository navigation
fix(executor): alternate rhs $ escape resolves at walk time (Refs #3116) - #3684
Merged
Merged
Conversation
) GNU subst.c:11614-11678 expand_word_internal's backslash branch consumes \\ before ANY character in an unquoted context and emits the character CTLESC-quoted, so \$ in a ${var:-word} alternate rhs is a literal $ that can never re-trigger expansion. The non-mut walker's unquoted backslash arm pushed the raw \\ and re-scanned $ as a live trigger; in the protect_ifs+protect_data walk (expand_parameter_word's rhs engine) live triggers now emit their carriers (DATA_DOLLAR / DATA_BACKTICK / ASSIGN_EXPANSION_BACKSLASH) at walk time, where quote state is still known. Pairs GNU leaves to quote removal (\q, \}, escaped whitespace) still fall through to the caller's trailing pass. Generated with [Devin](https://devin.ai) Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
This was referenced Nov 15, 2026
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.
Problem
echo [${x:-a\$b}]printed[ab]/[a\\bZZ]-style wrong output: in an unquoted${var:-word}alternate rhs, rubash pushed the raw\and let the next walk iteration re-scan$as a live expansion trigger.Root cause
GNU runs the alternate rhs through
parameter_brace_expand_rhs(subst.c:7966) →expand_string_for_rhs(subst.c:4462) →expand_word_internal(subst.c:11229), whose backslash branch (subst.c:11614-11678) consumes\before ANY character in unquoted context and emits the char CTLESC-quoted —\$is a literal$that can never re-trigger expansion.Rubash's non-mut walker (
expand_embedded_parameters_inner) only consumed\'/\"in the unquoted branch; every other pair fell through with the backslash emitted as text and the following char re-scanned live. The trailing context-freeunescape_unquoted_rhs_escapescould only save pairs that survive intact — hence $ (live trigger) was wrong while \q/} were right by accident.Fix
In the protect_ifs+protect_data walk —
expand_parameter_word's rhs engine (parameter_words.rs:291→311) — the backslash arm now resolves live triggers at walk time where quote state is still known:\$→DATA_DOLLAR,\``→DATA_BACKTICK,\→ASSIGN_EXPANSION_BACKSLASH carrier,\→line join,"/'keep their literal-char results. Pairs GNU leaves to quote removal (\q,}`, escaped whitespace→IFS_GLUE) still fall through to the caller's trailing pass unchanged.Gated on
protect_ifs && protect_data, which is exclusively the alternate-rhs walk (expand_embedded_parameters_protect_ifs_and_data); every other consumer is byte-identical.Test legs
cargo test --test issue3116_alternate_source_dollar_escape: 23/23 green (was 16/23 on master; the 7 RED cells were the $ live-trigger family)issue3117_alternate_dq_span_backslash: 11/24 now green (CBSDQUOTE cells $, \, ", `, \ all pass; the 13 non-CBSDQUOTE span cells are [bug] alternate word: dq-span \q wrongly unescaped (${x:-"a\qb"} yields [aqb] not [a\qb]) #3117's own fix)RUSTFLAGS=-D warnings cargo check --bin rubash: cleanrustfmt --edition 2021as sanctioned fallbackGenerated with Devin