Repository navigation
WIP: expansion/pattern cluster — #2441 dollar-bracket segment verdict, #2428 case-pattern expansion quotes, #2417 glued compound fan-out - #2451
Merged
Conversation
…e segment end
`echo "i=$["1]"]"` printed the literal text with status 0; GNU reports
`bad substitution: no closing `]' in i=$[` and discards the command
with status 1.
GNU mechanism: the double-quoted segment is delimited BEFORE
extraction — subst.c:1014 skip_double_quoted skips $( )/${ } units
and backquote mode but has no $[...] case, so the `"` after `$[`
closes the segment; extract_arithmetic_subst (subst.c:1300) then
runs extract_delimited_string (subst.c:1361) over the truncated
segment, and the extraction failure site reports the error and
jumps to top level with DISCARD.
Fix, three parts on the same mechanism:
- lexer (quotes.rs): the double-quote span copiers (cursor and char
forms) compare the extraction end (dollar_bracket_body_end, the
subst.c:1361 port) with the segment end (new dquote_segment_end,
the subst.c:1014 port). A span not contained in its segment is
copied only up to the segment end plus the closing quote (left
unconsumed, so the segment cooker closes there) and the cooked
word hands the walker the truncated span; a contained span copies
through its extraction end instead of plain bracket counting.
- collector (embedded_mutations.rs): segment-bounded mode for
raw-text walks inside a segment (in_double) — a raw `"` at the
body top level ends the collection unclosed instead of opening a
quote unit; nested $( )/${ } units still skip whole.
- walkers (embedded_parameters.rs, embedded_mutations.rs): an
unclosed collection raises no_closing_bracket_verdict
(command_subst_helpers.rs) on the shared DISCARD latch
(no_closing_brace_failure, consumed as ExpansionFailure(1)); the
@p prompt walk keeps its literal pass-through (subst.c:4407
no_longjmp_on_fatal_error). The named string is the whole heredoc
body for heredoc walks, else the walk's string through the
failing `$[` plus the body bytes before its first unescaped
quote.
Regression pins: tests/issue2441_dollar_bracket_quote_in_double_quotes.rs
(expectations measured on the GNU bash 5.3.20 oracle).
…s pattern quoting With p='"*"', `case '"xb"' in $p)` did not match: both case-pattern paths expanded first and then ran the EXPANDED text through decode_parameter_pattern_quotes, whose source-quote arms literal-mark the content of quote spans — killing the glob that arrived from the value. GNU: quoting is a read-time property only (parse.y read_token_word CTLESC marking, parse.y:5358-5398); patterns undergo no quote removal (execute_cmd.c:3733-3736) and expansion results carry no quoting, so quote characters in a value are ordinary data and glob characters next to them stay live (the `[[ == ]]` RHS path, quote_aware_glob_rhs, already treats results this way). Fix: decode_parameter_pattern_quotes splits into a shared impl with a source_quotes flag; the public entry keeps source mode for the parameter-pattern pipeline (which decodes masked SOURCE before expansion). The new decode_case_pattern_expansion runs in expansion-result mode — the `'`/`"`/`$'`/`$"` forms are copied as data while the backslash arm and the DATA_SQUOTE carrier arm keep their meaning — and both case call sites (expand_case_pattern_run and the quote-aware segment walk in compound_exec.rs) use it. The legacy strip_surrounding_quotes wrapping at both sites (and the now-dead helper) is gone: edge quotes in expanded text are data too. Source quote syntax never reaches the case decoder (any raw quote routes the pattern to the quote-aware segment walk, whose segments split at the quotes), and the #2421 escape-pair machinery in expand_case_pattern_run is untouched. Regression pins: tests/issue2428_case_pattern_expansion_quotes.rs (expectations measured on the GNU bash 5.3.20 oracle, including the filed repro verbatim).
…lements
`a=(pre"${arr[@]}"post)` with arr=(x y z) stored ONE element
`prex y zpost`; GNU stores three — prex, y, zpost. The whole-word
fan-out arms in the compound-assignment dispatcher only fire when
the list span is the entire element token; a glued token fell to
compound_plain_element_value_fields, which expands the token to one
joined string and stores it as a single quoted element.
GNU mechanism: arrayfunc.c:557 expand_compound_array_assignment
hands each element word to expand_words_no_vars, and
expand_word_internal produces a word LIST (subst.c: string_list_
pos_params for $@-shaped lists, the array value list for
"${name[@]}"): the span contributes one word per member and the
surrounding text glues to the first/last word.
Fix: glued_quoted_list_element_fields runs at the top of the
plain-element funnel. find_glued_list_span locates quoted list
spans (`"${name[@]}"`, `"${!name[@]}"`, `"${!prefix@}"`, `"${@}"`,
`"$@"`) in the token — raw `"`, hoisted ASSIGN_DATA_DQUOTE and `\"`
delimiter spellings, spans anywhere inside a quoted region, with
single-quoted text and $( )/${ }/backquote units skipped whole —
and the fold expands the text segments with the funnel's own
compound pipeline and splices in the members from the same sources
the whole-word arms use (array storage / dynamic stack view,
indirect keys, the ${!prefix@} name list in sort order, positional
parameters). Multiple spans fold sequentially (oracle-verified:
`("${a[@]}"_"${a[@]}")` gives x y z_x y z, not a cross product);
an empty list leaves the glued text as one element; `[*]` forms
keep their single joined element on the existing path.
Regression pins: tests/issue2417_glued_quoted_array_compound_assignment.rs
(expectations measured on the GNU bash 5.3.20 oracle).
caomengxuan666
marked this pull request as ready for review
November 1, 2026 09:07
This was referenced Nov 1, 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.
Refs #2441
Refs #2428
Refs #2417