Skip to content

WIP: rubash 2216+2217 — dollar-bracket arith in dquotes + expand_word result protection - #2226

Merged
caomengxuan666 merged 2 commits into
masterfrom
fix/2216-2217-walker-faces
Oct 30, 2026
Merged

caomengxuan666 merged 2 commits into
masterfrom
fix/2216-2217-walker-faces

Conversation

@caomengxuan666

Copy link
Copy Markdown
Member

Refs #2216
Refs #2217

Two sibling faces of the #2210 walker work, one commit per issue.

Refs #2217 — $[expr] inside double quotes (commit 50a31d9). The expansion walkers already had $[ arms; the gap was the lexer's double-quote cookers encoding the $ as DATA_DOLLAR before any walker could see it, and the raw span copiers ending a span at a " inside $[...]. Both cookers and both raw copiers now carry $[...] as one unit with plain bracket counting (the rule the parse.y hunt port and both walker collectors already use); cookers resolve \\/\" in the body, raw copiers stay verbatim. GNU: subst.c:10912 param_expand case [, subst.c:1301 extract_arithmetic_subst, subst.c:1361 extract_delimited_string, parse.y:3877 parse_matched_pair. New pins: tests/issue2217_dollar_bracket_arith_regressions.rs (8 tests).

Refs #2216 — redirect operands through the expand_word gate (commit 92e62e8). Ports #2210's protect+restore invariant to the non-mut walker behind a flag set only by the new expand_embedded_parameters_protecting_results entry, called only from expand_word's gated path; all other entries pass false, so the ~25 other consumers are byte-identical. User-data splice sites carry backslashes as ASSIGN_EXPANSION_BACKSLASH; expand_word restores the carrier right after its trailing unescape pass. GNU: subst.c:4773 quote_string, subst.c:11862 add_quoted_string, subst.c:4807 dequote_string. Pins: issue2210_redirect_target un-ignored + issue2216_redirect_comsub_trigger / issue2216_redirect_source_literal / issue2216_redirect_var_only_control.

Local verification (targeted, build slot): both pin files green (15 + 8 tests); script-file probe batteries byte-identical to the GNU oracle (bash 5.3.20) for the $[...] shape matrix, the redirect filename matrix, and the #2210 probe2/probe3 batteries. Full verification rides this PR's CI.

Known residual (documented in the cluster REPORT, not pinned): quote-state-aware delimited extraction for pathological shapes ($["1+1"] with unescaped quotes inside an enclosing dquote span; $[1\]] escaped close bracket) — GNU's extract_delimited_string tracks quote state while all rubash layers count brackets; master diverged on those shapes as well.

rubash#2217: old-style arithmetic $[expr] printed literally inside
double quotes (echo "x=$[1+1]" gave x=$[1+1]; GNU gives x=2). The
expansion walkers already had $[ arms; the gap was the lexer's
double-quote cookers in src/lexer/quotes.rs: a $ not followed by
(, {, a special, or a name-start was encoded as DATA_DOLLAR
(literal data), so the cooked word never presented a live $[ to
either walker. The raw double-quoted span copiers likewise ended
a span at a " inside $[...] (no $( -style skip).

Fix by mechanism, mirroring the existing $( handling in the same
functions: both cookers and both raw span copiers now recognize
$[ and copy the bracket body as one unit, with plain bracket
counting — the same rule the parse.y hunt port and both walker
collectors already use. Cookers additionally resolve \\ and \"
inside the body to the single character (the only resolutions
the arithmetic pre-expansion does not itself perform there);
raw copiers copy verbatim because their spans are re-cooked
later. GNU anchors: subst.c:10912 param_expand case '[' hands
the span to extract_arithmetic_subst (subst.c:1301), built on
extract_delimited_string (subst.c:1361), and evaluates through
the shared arithsub path (expand_arith_string with
Q_DOUBLE_QUOTES|Q_ARITH, subst.c:10868); parse.y:3877
parse_matched_pair counts brackets without quote tracking.

Regression pins in tests/issue2217_dollar_bracket_arith_regressions.rs
(8 tests: dquoted basic/variants/inner quotes/bad expression,
assignment positions, unquoted + heredoc controls, literal
contexts, unterminated EOF verdict), each verified against the
GNU oracle (bash 5.3.20) as a script file, red on master, green
here. Residual, deliberately not pinned: quote-state-aware
extraction for pathological shapes ($["1+1"] with unescaped
quotes inside an enclosing dquote span, $[1\]] close-bracket
escaping) — GNU's extract_delimited_string tracks quote state,
rubash's layers uniformly count brackets; master diverged on
those shapes too. See the cluster REPORT.

Refs #2217
rubash#2216: redirect operands expanded through the &self
expand_word gate hit the same trailing-unescape corruption
#2210 fixed in the &mut walker: with body='a\(b',
> "t_$((1+1))_$body" created t_2_a(b; GNU creates t_2_a\(b.
expand_word's trailing pass (unescape_remaining_shell_escapes
plus the \' collapses, gated on the source word containing $(
or a backtick) runs over the assembled string and cannot tell
expansion-data backslashes from deferred source escape pairs.

Port the #2210 protect+restore invariant to the non-mut walker
behind a flag scoped to the expand_word path only:

- expand_embedded_parameters_inner gains a protect_results
  parameter; every existing entry passes false (byte-identical
  behavior for all ~25 consumers: patterns, heredoc, compound
  assignments, parameter transforms, the braced-expansion tree).
- The new entry expand_embedded_parameters_protecting_results
  passes true and is called only from expand_word's gated path.
  In that mode, user-data splice sites (plain name, ${} result,
  $@, $*, positional digits) carry their backslashes as
  ASSIGN_EXPANSION_BACKSLASH — the registry carrier #2210 used —
  via protect_result_backslashes; data backslashes the walk
  itself emits (DATA_BACKSLASH restore at the tail, the literal
  fall-through push, single-quoted-span content) ride as the
  same carrier. Numeric-only arms ($?, $$, $!, $#, $-, $(( )),
  $[ ]) need no protection; command-substitution results already
  carry their own protection.
- expand_word restores the carrier to \ immediately after its
  trailing pass, unconditionally, so the carrier never leaks to
  callers when the gate does not fire.

GNU invariant (carrier justification per AGENTS.md, against
parse.y:5694-5706 got_escaped_character): expansion results
merged into a word are CTLESC-protected at splice time —
subst.c:4773 quote_string, applied at subst.c:11862
add_quoted_string — and subst.c:4807 dequote_string strips
only the protection bytes; assembled data is never re-scanned
as source. GNU redir.c redirection_expand receives the word
already protected the same way.

Pins: issue2210_redirect_target un-ignored (now green) plus
issue2216_redirect_comsub_trigger, issue2216_redirect_source_literal,
issue2216_redirect_var_only_control in
tests/issue2210_arith_dquote_rescan_regressions.rs; all #2210
pins in that file still pass. Verified byte-for-byte against
the GNU oracle as script files (redirect filename matrix and
the #2210 probe batteries).

Refs #2216
@caomengxuan666 caomengxuan666 changed the title WIP: fix/2216-2217-walker-faces — 0 in dquotes + expand_word result protection WIP: rubash 2216+2217 — dollar-bracket arith in dquotes + expand_word result protection Oct 30, 2026
@caomengxuan666
caomengxuan666 marked this pull request as ready for review October 30, 2026 13:54
@caomengxuan666
caomengxuan666 merged commit 1abb1ef into master Oct 30, 2026
12 of 13 checks passed
@caomengxuan666
caomengxuan666 deleted the fix/2216-2217-walker-faces branch October 30, 2026 13:54
caomengxuan666 added a commit that referenced this pull request Oct 30, 2026
Master carries PR #2218 (rubash#2211: comsub cd session-cwd anchoring, operand decline gates, logical_destination_display // seam fix in paths.rs), PR #2224 (census) and PR #2226 (walker) since this branch forked at 01836d3.

One conflict, in command_substitution_cd_pwd_output_impl (src/executor/command_substitution.rs), resolved as the union of both sides per the cluster REPORT overlap map:
- operand read stays quote-aware (split_shell_words_with_quote_info, #2219): the raw-empty decline is decided pre-expansion;
- #2211's post-expansion declines kept (leading '-', CDPATH search, expanded-empty) and operand_form is set only after every decline has passed;
- #2219's unquoted-blank (field-splitting) decline kept;
- downstream untouched: session-cwd anchoring (#2211), the cdable decline keyed on operand_form, and the #2220 logical rendering tail over paths.rs's seam-fixed logical_destination_display.

Re-verified on the merged tree (Linux): issue2219 9/9, issue2220 9/9 (incl. the //etc pin), issue2221 5/5, issue1415 adjacency 1/1, issue2211 14/14 (the session-// + relative-operand seam cells are pinned there), --lib 983 pass / 0 fail.
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