Repository navigation
fix(lexer): comsub heredoc gather ends at delimiter + IFS_GLUE record (Refs #4141) - #4165
Merged
caomengxuan666 merged 2 commits intoNov 24, 2026
Merged
Conversation
… (Refs #4141) A quoted comsub whose heredoc feeds a pipeline declined by the cat plan (plain sort / cat / a third stage models only [sort, -u]) falls to the real executor, which re-tokenizes the extracted body. In that text the delimiter line carries the reader's IFS_GLUE record byte in place of the consumed closing paren, and feed_awaiting_body's in-comsub trailing-residue arm required the rest after the delimiter to trim to empty — 0x1c is not whitespace — so the line failed every terminator arm and was pushed into the body (the delimiter line leaked into the captured output). GNU gather_here_documents (make_cmd.c:602) ends the document at the exact delimiter line; the PST_EOFTOKEN arm (make_cmd.c:606-611) ends it at the delimiter followed by the substitution's EOF token. In the extracted body the EOF token is already consumed and the glue record is its only trace, so the residue test now ignores IFS_GLUE before the trim check: delimiter + glue/whitespace terminates, delimiter + real words still does not.
…ifs_glue (Refs #4141) The heredoc gatherer's in-comsub arm stripped the reader's IFS_GLUE record from the post-delimiter residue with a bare .replace() keyed on the registry const. The marker-lint L3 gate rejects needle operations on registry consts at unreviewed sites: a blind replace cannot see the escape pairs that make a typed marker char data (rubash#2885 E7), so marker surgery belongs in src/executor/markers.rs. Move the strip into a new pair-aware helper there, markers::strip_ifs_glue: IFS_GLUE is a prefix carrier (protect_ifs_chars splices it in front of the character it protects), so the walk drops every bare glue byte and copies the protected data char verbatim. A user-typed U+001C never arrives as a bare char — typed C0 data rides raw-byte marker pairs, whose codepoints are distinct and pass through untouched — so the strip cannot fold data into protocol. Output is byte-identical to the .replace() it supersedes; the lexer's residue test, its #4141 comment, and the guard behavior (delimiter + real words still does not terminate) are unchanged. marker-lint: OK (was 1 violation at src/lexer/mod.rs:1213). Unit pin: strip_ifs_glue_drops_carrier_preserves_data.
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 #4141. UNVERIFIED-BY-CAPTAIN.
Mechanism (diagnosed before touching code)
Shape:
echo "$(cat <<E | sort\nbody\nE)"printedE\x1c+bodyinstead ofbody.Route map, measured against the cloud GNU 5.3.20 oracle with script-file batteries:
catheredoc comsub plan models at most the[sort, -u]pipeline arm (heredoc_comsub_produce). A plainsort, acatsecond stage, or a third stage declines at produce time and the body falls to the real executor (command_list_substitution_output_typed), which re-tokenizes the extracted body text.)to record that the substitution closed on the delimiter line, and extraction consumes the)itself, leavingE\x1c. The plan route strips IFS_GLUE wholesale before tokenizing, so it never saw the byte.feed_awaiting_body(src/lexer/mod.rs), compares the raw line against the delimiter. Its in-comsub trailing-residue arm required the rest after the delimiter totrim()to empty —\x1cis not whitespace — so the line failed all four terminator arms and was pushed into the body, leaking into the pipeline's input.Leak class (oracle-verified): quoted comsub + plan-declined pipeline +
E)delimiter line — plain sort, sort with multi-line body, pipe to cat,<<-tab form, body with expansions, quoted delimiter, three-stage pipeline all leaked. Already correct and kept correct:[sort, -u](plan), non-piped quoted, assignment form, unquoted form, plain heredoc outside a comsub.GNU basis
gather_here_documents(third_party/bash/make_cmd.c:602) ends the document at the exact delimiter line; the PST_EOFTOKEN arm (make_cmd.c:606-611) ends it at the delimiter followed by the substitution's EOF token. In the extracted body the EOF token is already consumed; the glue record is its only trace.Fix (single mechanism)
The in-comsub residue arm's invariant was wrong, not incomplete: the residue after the delimiter is reader-side residue (whitespace, or the reader's own glue record), never body text. The arm now removes IFS_GLUE from the residue before the trim check. Delimiter + glue/whitespace terminates; delimiter + real words (
E more) still does not. No body bytes change — only the terminator decision. This corrects the predicate for the whole class (rubash#117 sanctioned move 1); it adds no per-symptom guard.What this PR deletes
Nothing structural: it deletes the false invariant that the post-delimiter residue consists solely of whitespace. No code path, arm, or mechanism is removed; no new mechanism is added.
Net lines
Evidence
tests/issue4141_quoted_comsub_piped_heredoc_delimiter_regressions.rs— 4 of 5 red on pristine masterd5ae7bfb, every red solely theE\u{1c}stdout leak (all stderr assertions already green pre-fix); the adjacent-routes guard green pre-fix by design. Post-fix 5/5 green in both locales.~/oracle/bash-5.3.20/bin/bash): bug shape and the adjacency scripts byte-identical on stdout AND stderr; the wide battery byte-identical on stdout.cargo test --lib lexer::112/112. rustfmt clean on both files.Honest notes (pre-existing, NOT this issue, untouched)
heredoc_regressionshas one failure on pristine master too (unterminated_heredoc_with_backslash_newline_warns_at_last_physical_line: probe-script write NotFound in this sandbox) — verified by stash A/B; environment face.E)form and the three-stage form emit no delimited-by-end-of-file warning in rubash where GNU emits one; one sequence shape (redirect +;inside the comsub) reports the warning at a different line than GNU. Output bytes are correct in all three; recorded here for the captain's triage.