Repository navigation
fix(lexer): comsub heredoc header scan takes <<< as one operator (Refs #4193) - #4196
Merged
Merged
Conversation
…efs #4193) GNU read_token (parse.y:3689-3703) decides the redirect operator by maximal munch at the first '<': '<<' plus a third '<' is LESS_LESS_LESS, the here-string token - never a '<' followed by a heredoc '<<'. The lexer's comsub-heredoc header scan stepped over only the first '<' of '<<<', so the remaining '<<' was read as a heredoc header whose delimiter was the here-string word itself ('$(cat'). That bogus header queued ahead of the real one in comsub_heredocs, so when the delimiter line ('E)') arrived it matched neither the queue front's close nor its delimiter-line mark, the IFS_GLUE record byte was never spliced, and a here-string-fed comsub lost its here-document end-of-file warning entirely (make_cmd.c:627 warns per heredoc occurrence). Skip all three bytes of '<<<' in the header scan, mirroring the token rule. The real header inside the here-string word now queues and marks exactly as on the command-word path, and the warning flows through the family's single existing emission site; no second warning site is added and no mechanism is deleted - the bogus header is gone by construction. Net: src +14/-0, tests +132 (6 pins: 4 discriminating fail-first, 2 guards, dual locale).
Member
Author
|
CAPTAIN-VERIFY — merging. Reviewed head
Net: src +14/−0, tests +132. |
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.
UNVERIFIED-BY-CAPTAIN — code-only lane delivery. Refs #4193.
Defect
A command substitution fed by a here-string lost its here-document end-of-file warning entirely:
GNU bash 5.3.20 warns (
warning: here-document at line 1 delimited by end-of-file (wanted \E')); rubash emitted nothing. Same on the simple-command formread x <<< $(cat <<E ...)`.Root cause
The lexer's comsub-heredoc header scan (
scan_line_for_comsub_heredoc_headers) stepped over only the first<of<<<, so the remaining<<was read as a heredoc header whose delimiter was the here-string word itself ($(cat). That bogus header queued ahead of the real one incomsub_heredocs; when the delimiter line (E)) arrived it matched neither the queue front's close nor its delimiter-line mark, the IFS_GLUE record byte was never spliced, and the substitution's heredoc plan never saw the record the warning keys on.GNU decides the operator by maximal munch at the first
<(parse.y:3689-3703read_token:<<+<is LESS_LESS_LESS, one here-string token). The warning itself is make_cmd.c:627's per-occurrence warning — the family's single existing emission site; this PR adds no second one.Fix
One match arm in the header scan: in unquoted state,
<<<is skipped as a single 3-byte operator, mirroring the token rule. The real header inside the here-string word now queues and marks exactly as on the command-word path.<<<</<<<<<compose as GNU's<<<+</<<<+<<.Deletion section
No mechanism deleted. The bogus header's production path is eliminated by construction (the tail
<<of a here-string operator no longer reaches the heredoc arm).Net lines
src/lexer/mod.rs, one match arm + comment)Verification (lane-side)
<<-, and properly-closed here-string forms, plus all command-word controls). The 3 remaining diffs are the pre-existing residuals below.tests/issue4193_herestring_comsub_heredoc_warning_regressions.rs, dual locale C/C.UTF-8): fail-first established — on pristine, exactly the 4 discriminating pins are red (stderr empty) and the 2 guards green; with the fix, 6/6 green.unix_file_unary_operators_check_file_types_and_mode_bits, reproduces identically on pristine — sandbox file-mode environment artifact, unrelated). rustfmt clean on both changed files.Frontier residuals (not fixed here, not filed)
line 5 / at line 3vs GNU'sline 3 / at line 1. Proven independent of here-strings and of this fix: a plain< $(cat <<E ...)redirect word on a while command produces the identical attribution on pristine — compound-command redirect words are unstamped and keep the legacy seed (the comsub heredoc warnings: line attribution seeds from command start; same-text dedup swallows distinct occurrences #4190 frontier). The while pin therefore asserts the warning's presence and text, not its line numbers; the simple-command pins are byte-exact including lines.$(cat <<E; cat <<F ... F)warns forEwhere GNU warns forF. Identical on the command-word path (untouched by this PR); after this fix the here-string form matches the command-word form byte-for-byte.src/lexer/quotes.rs:1415(quote-removal copy) has a<<guard of the same shape and may misread the tail of<<<as a heredoc skip. The proven [bug] herestring-fed comsub loses the heredoc EOF warning entirely (IFS_GLUE marker dropped on the herestring path) #4193 path does not pass through it (plan source and output were correct); no differential probe was run against it.Full lane record:
lane-4193-exec-2026-11-25.mdin the patrol dossier.