Skip to content

Fix compound-assignment field split of decoded $'…' blanks in mixed-quote elements (Refs #4200) - #4286

Merged
caomengxuan666 merged 3 commits into
masterfrom
captain/4200-ansic-glue
Nov 29, 2026
Merged

caomengxuan666 merged 3 commits into
masterfrom
captain/4200-ansic-glue

Conversation

@caomengxuan666

Copy link
Copy Markdown
Member

Refs #4200. UNVERIFIED-BY-CAPTAIN.

Boundary mapping of #4200 on current master (60ed70e5), all forms compared byte-for-byte (stdout/stderr/rc) against GNU bash 5.3.20 with script-file probes:

  • The title shape f=('a'"b"'c) and every other mixed-quote element form from the issue are already correct on master (fixed by fix(expand): single-quote backslash is data — one pass_next quote-state rule (rubash#4195) #4201 or an earlier quote-span commit) — pinned by the new tests so they cannot regress silently.
  • One residual face remained: in a plain (unsubscripted, non-declare) compound assignment, an element concatenating a $'…' segment with another quoted segment had its ANSI-C-decoded blank bytes (\t, \n) replaced by spaces — f=('a'$'x\ty') stored ax y instead of ax<TAB>y.

Root cause: the compound walker correctly decodes $'…' and re-wraps it in raw '…' text with the U+E401 ANSI_C_IFS_GUARD marker intact, but split_requoted_hoisted_compound_word had no arm for the guard and does not track raw '…' as a span, so the guarded byte fell to the bare-IFS arm and the element was field-split (then re-joined with a space). GNU never splits here: parse.y:5564-5571 hands the decoded span back wrapped by sh_single_quote.

Fix (single mechanism, +16 lines in src/executor/assignment_expansion.rs): a new ANSI_C_IFS_GUARD arm in split_requoted_hoisted_compound_word glues the guard and the following byte into the current field; the storage unquote already strips the guard.

Tests: 14 new pins in tests/issues_4200_4299/issue4200_compound_mixed_quote_elements.rs (title forms, EOF-unclosed diagnostic, all corrupting shapes, and the control shapes: whole-element $'…', declare/subscript forms, TAB-valued IFS, quoted parameter tab, and the GNU field-split of unquoted command substitution). Bucket: 52/52 pass; array_compound_quote_regressions: 18/18.

Not in this PR (characterized in the lane dossier for a separate ticket): when a malformed compound assignment's quote spans into the next line, GNU reports the error at the offending token's line, discards the command, and continues; rubash reports at the assignment's first line and aborts. Same-line forms already match GNU on both sides.

…lements

In a plain compound assignment, an element concatenating a $'...'
segment with another quoted segment had its decoded blank bytes
(tab, newline) replaced by spaces: f=('a'$'x\ty') stored 'ax y'
instead of 'ax<TAB>y'. The compound walker decodes $'...' and
re-wraps it in raw quotes with the U+E401 ANSI_C_IFS_GUARD marker
intact, but split_requoted_hoisted_compound_word had no arm for the
guard, so the guarded byte fell to the bare-IFS arm, was field-split
and re-joined with a space. GNU hands the decoded span back wrapped
by sh_single_quote (parse.y:5564-5571) and never splits it. A new
guard arm glues the guard and the following byte into the current
field (+16 lines, single mechanism). The issue's title forms were
already correct on master; 14 new pins cover them plus every
corrupting and control shape. Bucket 52/52.

Refs #4200 (not Fixes).
@caomengxuan666
caomengxuan666 merged commit 5ff7280 into master Nov 29, 2026
11 of 13 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