Skip to content

fix(executor,lexer): #880 rework -- close the two PR#898 review blockers - #936

Merged
caomengxuan666 merged 2 commits into
masterfrom
cr-fix/898
Oct 20, 2026
Merged

caomengxuan666 merged 2 commits into
masterfrom
cr-fix/898

Conversation

@caomengxuan666

Copy link
Copy Markdown
Member

Summary

Implements the REQUEST-CHANGES review findings on #898 (comment 6290178882), built directly on top of the original author @a-rookie-of-C-language's branch head 80aea329. maintainerCanModify is false on #898, so this lands as a follow-up PR — original authorship is preserved (the base commit is theirs); whichever of the two PRs merges first wins.

  • Blocker 1 — Face 2 command words bailed 100%. The simulator's in_double backtick arm pushed DATA_DQUOTE (\x18) for \", but the cooked word holds a bare " (0x22) — copy_backtick_body_cursor(dq=true) folds the escape (GNU subst.c:921-931 string_extract_double_quoted stripdq arm). simulated != cooked guaranteed a bail on any command word carrying an unquoted expansion sibling. Now pushes '"'. printf '<%s>\n' "a b\echo "x"`"$w→ ` (matches WSL GNU 5.3.0).
  • **Blocker 2 — \`` inside a $()-nested backtick closed the span early.** copy_comsub_body_verbatim_for_ifs_marking's backtick-body _arm single-stepped after pushing`, so the escaped backtick was re-read as a closer and the leftover ) then closed the $(); the tail re-walked as outer text and desynced the cook. Now consumes \+escaped as a pair, arm-for-arm with copy_backtick_body_preserving_syntax(_dq) / copy_backtick_body_cursor. printf '<%s>\n' "a b"$(echo \echo \`echo \\)`\ \\$y) → <a b)> <$y> (matches WSL GNU 5.3.0).
  • Major 3 — merged the two outer backtick arms into one dq = in_double arm, so the unquoted arm also elides \<newline> / \<CRLF> exactly like copy_backtick_body_cursor does under either flag (previously latent because GroupScanFeeder::push_main_line strips main-line continuations).
  • Review point 4 — $"..." cooked through preserve_backticks=false. The command-word walk shipped the backtick body's \" as DATA_DQUOTE data, so $"a b\echo "x"`"$wprinteda b"x"p. Flipped to true: $"cooks by the same double-quote rules as"(the locale prefix is translation markup only;subst.c:925-932backquote mode applies identically) — this also matches the assignment walk's$"arm, which already passestrue. Note this was *required* alongside Blocker 1: with the simulator now emitting the correct bare ", the wrong cooked side would have regressed the shape from "wrong chars" to "wrong chars + split". Both point-4 forms now match GNU ( `).

Test plan

  • cargo test --test issue880_comsub_case_ifs_mark_regressions — 10/10 (4 new command-word reproducer tests from the review)
  • cargo test --test issue868_carrier_ifs_mark_regressions — 7/7
  • cargo test --test issue876_multibyte_quoted_ifs_mark_regressions — 7/7
  • cargo test --lib — 707/707; --test lexer_quote_tests 16/16; quote_in_double_quote 4/4; marker_leak_golden 8/8; assignment_quote_roundtrip 9/9; array_compound_quote 13/13
  • --test regression 77/78 — sole failure upstream_suite_slice_snapshots ("no suite files under third_party/bash/tests", worktree lacks the vendored subtree; same environment-bound failure the reviewer noted in the master baseline)
  • Manual probes (script files, rubash.exe): p03 <a bxp>/<q>, p08 <a b)>/<$y>, p4a $" form <a bxp>/<q>, p4b $(...) sibling <a bxp>/<q> — all byte-equal to the GNU 5.3.0 columns quoted in the review

Refs #898, #880

Generated with Devin

arookieofc and others added 2 commits October 20, 2026 00:33
… bail blind spots

GNU parse.y:4451 parse_comsub re-parses the $(...) body with the real
grammar, so a case clause owns its pattern `)` (parse.y:3465-3468
special_case_tokens); and subst.c:921-931 string_extract_double_quoted
folds \" to a bare `"` while scanning the enclosing quotes (stripdq arm).

The IFS-marking simulator replayed neither rule, and replayed no backtick
line-continuation rule either, so any word pairing a quoted IFS char with
one of these shapes desynced the simulated cook, hit the equality-guard
bail, and split its quoted IFS:

- dquote-wrapped backtick kept `\"` verbatim while the cook folds it
  (`a="`echo \"x\"`"` gave `"x"` for `x`); the chars-iterator backtick
  copier gains the dq flag and the dquote walker passes dq=true
  (outer backticks unchanged). The simulator's dquote backtick arm
  replays the same fold plus `\<newline>` elision.
- backtick `\<newline>` / `\<CRLF>` elision was not replayed in the
  simulator's dquote backtick arm.
- `$(...)` used a naive paren depth count that closed early on
  `$(case x in ...)` pattern parens; the tail was re-walked as outer
  text, so a `\`/`"`/`'` there desynced the cook and split quoted IFS
  (e.g. `"a b"$(case x in x) echo \$y;; esac)` gave `a` + `b$y`).
  Now case-aware, arm-for-arm with copy_dollar_paren_body_raw via the
  shared update_command_substitution_case_depth machine (parse.y:3710/
  3759, 3181/3183, 3630-3643; rubash#276/#284/#380/#513), with opaque
  quote/comment/nested-$() span skips (widened to pub(crate) with a
  lexer-level re-export).

Mismatch still bails (safe direction); fixed shapes no longer bail.

Evidence: target/probe/880r.sh + 880s.sh + 880t.sh + 880u.sh byte-match
WSL GNU Bash 5.3.15; new tests/issue880_comsub_case_ifs_mark_regressions.rs
6/6; #868 7/7 + #876 7/7; regression 78/78; lib 706 + 1 pre-existing
env-flaky windows_listing_cache (fails on clean master too).
Addresses the REQUEST-CHANGES findings on PR#898 (which builds on the
same #880 mark_quoted_ifs_from_raw simulator approach):

- The in_double backtick arm of the simulator pushed DATA_DQUOTE where
  the cooked word holds a bare '"' — copy_backtick_body_cursor(dq=true)
  folds \" to 0x22 (GNU subst.c:921-931 string_extract_double_quoted
  stripdq arm), so simulated != cooked bailed on every command-word
  shape with an unquoted expansion sibling. Push '"' instead.
- copy_comsub_body_verbatim_for_ifs_marking's backtick-body '_' arm
  single-stepped after pushing '\', letting an escaped ` close the
  backtick early so a leftover ) closed the $() and the tail re-walked
  as outer text. Consume backslash+escaped as a pair, arm-for-arm with
  copy_backtick_body_preserving_syntax(_dq).
- Merge the two outer backtick arms into one dq=in_double arm so the
  unquoted arm also elides \<newline>/\<CRLF>, matching
  copy_backtick_body_cursor's dq-independent elision.
- Face 2 family (review point 4): $"..." on the command-word walk
  routed through remove_double_quoted_into_cursor(preserve_backticks=
  false) and shipped the backtick body's \" as DATA_DQUOTE data.
  Flip to true — $" cooks by the same double-quote rules as " (the
  locale prefix is translation markup only; subst.c:925-932 backquote
  mode applies identically), matching the assignment walk's $" arm.

Regression tests add the command-word reproducer forms from the
review (dquote backtick + unquoted sibling; nested escaped backtick
inside $(); $" and $(...) sibling variants).

Generated with [Devin](https://devin.ai)

Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
@caomengxuan666
caomengxuan666 merged commit b934174 into master Oct 20, 2026
8 checks passed
@caomengxuan666
caomengxuan666 deleted the cr-fix/898 branch October 21, 2026 08:08
caomengxuan666 added a commit that referenced this pull request Oct 21, 2026
…span (#977)

fix(executor): ${...} IFS-mark copy arm uses the cook's own dolbrace span (#977)

mark_quoted_ifs_from_raw's ${...} verbatim copy arm scanned the body with
a naive {/} depth count plus a backslash skip: a } inside '...'/"..."/
`...`/$(...)/nested ${...} was counted as the close, the span ended
early, the tail re-walked as outer text, the simulated cook diverged
from the real one and the equality guard bailed the whole mark pass --
quoted IFS chars lost \x1c protection and field-split ("a b"${x:-'}'}$w
printed <a> <bVp> <q>).

GNU anchors: parse.y:3877 parse_matched_pair (P_FIRSTCLOSE|P_DOLBRACE,
called for ${...} from read_token_word at parse.y:5513) skips quoted
regions, command substitutions and nested braces opaquely, and counts a
nesting level only for ${ -- a bare { never nests.

The arm now delegates the span end to the same functions the cook's own
${ path runs -- lexer/quotes.rs copy_braced_parameter_unquoted_cursor
(outer) / copy_braced_parameter_after_dollar_cursor (inside "...",
dolbrace.rs scan_braced_parameter underneath) -- so the simulated
boundary is the cooked boundary by construction (same per-arm
replication pattern as the #936 $(...) arm). posix_mode_enabled() is
plumbed through for the inside-double-quote Interp 221 context, matching
copy_braced_parameter_after_dollar's context argument.

Fixes #977

Generated with [Devin](https://devin.ai)

Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
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.

2 participants