Repository navigation
Release unclosed-case bodies at the completeness gate (stacked on the read-time validation change) - #3303
Merged
Conversation
This was referenced Nov 10, 2026
caomengxuan666
added a commit
that referenced
this pull request
Nov 11, 2026
Refs #2789 ## What this changes GNU validates a substitution body when the enclosing command is read (parse.y:4451 parse_comsub hands the body to the grammar; `)` is the substitution's shell_eof_token, parse.y:4519-4521). Rubash screened bodies only on execution paths, so a body the program skips never reported, and an executed body in a -c string missed the 127 remap (shell.c:1471-1472). - `src/script_driver.rs` (+16): the grouped reader screens each freshly parsed non-interactive unit before execution and before unit voiding; interactive readers and diagnostic-owned prefix runs are unchanged. - `src/executor/command_substitution.rs` (+373, plus the +4/−3 marker-lint rework): `screen_comsub_bodies_at_read` plus a recursive walker over process-substitution bodies, word-shaped texts and nested command bodies. Word texts are re-extracted with a live-context scan (single-quoted and backslash-escaped openers are literal and yield no node). Backquote subtrees are skipped (GNU parses those in the substituted child); here-document bodies are data and never walked. On a hit the error is reported once through the existing body-error report — with the parked marker's body-relative lines translated into the reader unit's frame — and the unit aborts with the driver's own status (-c 127, file 2). - `src/parser/command_substitution.rs` (+182): live-context word scan, and the in-field unclosed-case reclassification: a `)` that cannot close any pattern (armed pattern region with no content yet, or glued to `in` or to the case subject) ends the substitution, so the truncated body gets the body parser's grammar verdict instead of an unclosed-EOF classification. - `src/parser/mod.rs` (+7): executor-facing wrapper for the live scan. - `scripts/marker-lint-allowlist.txt` (+1): the U+0001 intra-record separator literal of the `__RUBASH_PARSE_ERROR_COND__` payload is allowlisted (no registered constant exists for this codepoint; producer and same-shape consumers share the allowlist precedent). Marker-lint whole-tree passes. ## 本 PR 删除了什么 No tracked file is deleted and no product line is removed: the change is +580/−0 across the five files above. The lane-local probe file used during development was untracked and was removed before the commit; it was never part of the tree. ## Verification (merge round, on the merged tree) Captain review: `~/workspace/review-3282/CAPTAIN-VERIFY.md`; the gate interaction was measured independently in the PR #3303 captain review (§3 of its CAPTAIN-VERIFY). - Pin `issue2789_comsub_read_time_validation` on the merged tree: 9 passed / 0 failed. (The three cells red on the lane's stale base were the completeness-gate face; on the current base this stack's pin already measures 9/9. The gate itself is PR #3303, stacked behind this PR.) - Neighbor stems (12): all green. - Lib tests, merged head vs current master: failure name sets empty on both sides (bin built first on both trees). - `cargo fmt --check`: clean. Marker-lint whole-tree: clean. UTF-8 boundary hygiene whole-tree: clean. - `RUSTFLAGS="-D warnings"` on this change's own targets: clean. Whole-tree stops only at pre-existing base test-target defects byte-identical between base and head (recorded in the captain review). - CI: all checks finished; zero failures outside the master baseline set; ledger canary green. #2789 stays open: its remaining faces (the completeness gate in PR #3303 and the residuals filed from that review) are accounted separately; the captain rules its closure after the gate merges.
…tion arm Three trigger predicates (armed empty region / paren glued to `in` / paren glued to the subject) and four non-trigger controls, per the captain review of the P4B read-time validation work. The space-variant test is the fail-first witness for the completion latch that lands in a later commit: at this commit it fails, the other seven pass. GNU anchor: parse.y:4451 parse_comsub, parse.y:4519-4521 shell_eof_token. Refs #2789
The pop arms of the completeness gate (oracle unclosed_input_close_char_posix and its staged twin close_char_residuals_advance) detained any ')' while a case opened inside the unit was deeper than at push, so '$(case x in ...)' unit bodies could not reach the parser whenever the pattern-content witness could not tell the shape apart: a pattern separator tail (a|), the pattern-list opener ((), an outer case's pattern setting the witness for an inner substitution, and a clause terminator in the still-empty region (a;;). Both implementations now carry the parser arm's pattern-content bookkeeping (case_pattern_content / case_pattern_paren_depth / case_pattern_opener_available / case_pattern_region_seen — in the staged twin as checkpointed CloseCharResidualState fields, so a parked scan resumes with the same judgment) and judge the pop arm by a pre-update snapshot: the ')' closes the delimiter when the armed region has no content yet, or it is glued to 'in', or glued to the case subject — the same three conditions the parser arm in dollar_command_substitution reclassifies by (parse.y:4451 parse_comsub takes the whole unit; parse.y:4519-4521 raises the grammar error there). The detention boundary is unchanged: only a case opened inside the delimiter is judged, and a ')' after real pattern content is still held. Non-regression surfaces: the staged-vs-oracle equivalence module gains the released shapes plus controls at every line prefix; src/lexer/tests.rs gains the gate-verdict test. UnclosedDelim, the staged case-depth function body, and the funsub / pattern_paren / arith arms are untouched.
'$(case x in )' (space before the paren) could not reclassify: when
'in' completes at a blank, the reserved-word machine's word-boundary
preempt zeroes the stage before the pattern region arms, so none of
the close arm's three conditions sees the shape and the extractor
scans off the end of the word.
dollar_command_substitution now latches the completion: a pre-update
capture notes the char that completes 'in' at stage 2, the latch is
applied after the region bookkeeping (so the disarm-clear cannot
erase it in its own iteration), pattern-content chars and region
disarm clear it, and the close arm accepts it as a fourth condition.
The glued forms keep judging by conditions (a)-(c) exactly as
before; '$(case x in a)' still yields no truncation because the
pattern char clears the latch.
Pinned by the extractor unit test
reclassifies_space_variant_via_completion_latch (fail-first against
the pre-latch tree: None where Some("case x in ") is required).
caomengxuan666
force-pushed
the
fix/gate-case-2789
branch
from
November 11, 2026 00:07
484eda3 to
f9efa65
Compare
caomengxuan666
marked this pull request as ready for review
November 11, 2026 00:30
caomengxuan666
added a commit
that referenced
this pull request
Nov 17, 2026
… (Refs #3307) (#3756) The non-interactive gate (#3303) releases unclosed-case comsub units whose armed pattern region has no content yet, but the three #2784- witness unit scans (Lexer::skip_cmd_subst, skip_parenthesized_unit_ corrected and its staged mirror skip_parenthesized_unit_corrected_ex) carried no equivalent predicate, so the interactive face held separator-tail shapes such as `echo $(case x in a|)` to PS2 while the gate released them. Port the gate/parser arm's per-pattern content bookkeeping (content, paren depth, opener availability, pending-opener count) into all three scans and add the reclassification predicate `(region_before && !content_before)` to their `)` arms. Tests: tests/issue3307_repl_unclosed_case_comsub.rs (fail-first: the two released-family tests fail on the base tree). Co-authored-by: caomengxuan666 <[email protected]>
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 #2789
What this does
Stacked on the read-time validation change (the two carried commits at the bottom of this branch are that change, verbatim): the completeness gate in
src/lexer/continuation.rsheld any)hostage while acaseopened inside the unit was deeper than at push, so an unterminated-case body such as$(case x in)died as an unclosed-EOF (status 2) before the parser could classify it — where GNU's body parser owns the paren (parse.y:4451parse_comsub; parse.y:4519-4521shell_eof_token) and raises a grammar error (-c: 127, file: 2).The gate's existing pattern-content witness (#2784, refined by #3241) cannot judge shapes where the witness stays set or never applies: a pattern separator tail (
a|), the pattern-list opener (()), an outer case's pattern polluting the witness for an inner substitution, and a clause terminator in the still-empty region (a;;).Changes
src/lexer/continuation.rs— both gate implementations (the one-shot oracleunclosed_input_close_char_posixand its staged twinclose_char_residuals_advance) now carry the parser arm's pattern-content bookkeeping (case_pattern_content,case_pattern_paren_depth,case_pattern_opener_available,case_pattern_region_seen); in the staged twin the four live as checkpointedCloseCharResidualStatefields so a parked scan resumes with the same judgment. Each pop arm judges by a pre-update snapshot (region/content/stage/word captured before the case-depth update, carried to the pop arm in the same iteration): the)closes the delimiter when the armed region has no content yet, or it is glued toin, or glued to the case subject — the same three conditions the parser arm reclassifies by. The detention boundary is unchanged: only a case opened inside the delimiter is judged, and a)after real pattern content is still held.src/parser/command_substitution.rs— a completion latch for the spaced variant$(case x in ): whenincompletes at a blank, the reserved-word machine's word-boundary preempt zeroes the stage before the pattern region arms, so no close-arm condition can see the shape. The latch is noted at the completion char, applied after the region bookkeeping, cleared by pattern content and by region disarm, and accepted as a fourth close condition. Also: extractor unit tests that pin the reclassification arm directly (three trigger predicates, four non-trigger controls, the latch pair) — the arm is unreachable on every product path while the gate detains the unit, so these tests are its independent proof.tests/issue2789_comsub_read_time_validation.rs— two added cells: the spaced variant via-caborts 127, and the spaced variant followed by a second substitution via-caborts 127.src/lexer/tests.rs— gate-verdict test for the released shapes and the two controls.本 PR 删除了什么
Nothing. The change is purely additive bookkeeping plus tests; no code path, arm, or test was removed or narrowed. (
UnclosedDelim, the staged case-depth function body, and the funsub / pattern_paren / arith arms are untouched by design.)Verification
left: None, right: Some("case x in "). After this change: 8/8.case a in a) echo $(case x in);; esac: 2 → 127 (an outer case's pattern no longer detains the inner unit).echo $(case x in ) $(echo ok): silently accepted (0) → 127. Without the latch the extractor scans past the case's own)to the next substitution's close, so the malformed body is never bounded at all.case_pattern_paren_does_not_close_command_substitutionstill holds ($(case x in a) echo x)stays detained). The pattern-list opener shapes are agreement shapes only: the opener disarms the region (stage 4) in both machines, so both still hold the unit — recorded as a residual, not coverage.evalover a runtime-assembledecho $(case x in)): 127 with a syntax diagnostic, matching GNU's classification.issue381_empty_case_stray_delimiter_regressions, whose 3 red cells reproduce byte-identically on the base tree — a pre-existing harness artifact (its stderr normalizer mangles the prefix when the binary path ends inrubash), not a regression of this branch; the product behavior (status 2, token, line, echoed line) matches expectations on all three trees.RUSTFLAGS="-D warnings"on the lib and bins rc=0;cargo check --testsrc=0;cargo fmt --checkrc=0;scripts/check-marker-literals.pyrc=0;scripts/check-utf8-boundary-hygiene.sh(whole tree) rc=0.Notes for the merge round
bc049e16) is clean.a|,a;;), so those keep the EOF classification (status 2) end to end even though the gate now releases them — the gate/extractor machine divergence predates this change; and the skip-path family inskip.rscarries no equivalent of this predicate, so the compositehas_unclosed_input_syntaxstill judges these units unclosed for the interactive feeder.