Skip to content

fix(lexer): comsub heredoc header scan takes <<< as one operator (Refs #4193) - #4196

Merged
caomengxuan666 merged 1 commit into
masterfrom
fix/4193-herestring-glue-marker
Nov 25, 2026
Merged

caomengxuan666 merged 1 commit into
masterfrom
fix/4193-herestring-glue-marker

Conversation

@caomengxuan666

Copy link
Copy Markdown
Member

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:

while read x; do echo "got $x"; done <<< $(cat <<E
body
E)

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 form read 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 in comsub_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-3703 read_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: +14/−0 (one file, src/lexer/mod.rs, one match arm + comment)
  • tests: +132 (new file, 6 pins)

Verification (lane-side)

  • Oracle battery: 13 script-file shapes, stdout/stderr captured separately and byte-compared against cloud GNU bash 5.3.20 — 10 byte-identical (incl. simple-command, quoted-word, <<-, and properly-closed here-string forms, plus all command-word controls). The 3 remaining diffs are the pre-existing residuals below.
  • Pins (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.
  • Adjacent families: issue4140/4169/4190 suites + 18 heredoc/herestring/comsub targets — 107/107. Expanded sweep: all 137 test targets matching heredoc|comsub|herestring|backquote — 1047 passed / 0 failed. Lib: 1314 passed, 1 failed (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)

  1. Redirect-word line seed on compound commands: the while-loop shape now warns, but with lines line 5 / at line 3 vs GNU's line 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.
  2. Two-heredoc plan attribution: $(cat <<E; cat <<F ... F) warns for E where GNU warns for F. 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.
  3. Same-shaped mis-split in a second walker (unprobed): 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.md in the patrol dossier.

…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).
@caomengxuan666

Copy link
Copy Markdown
Member Author

CAPTAIN-VERIFY — merging.

Reviewed head 079a682 (base a02758b9). The herestring warning fix for #4193:

  • Root cause, sharper than the filing's hypothesis: the lexer's comsub-heredoc header scan steps over only the first < of <<<, reads the remaining << as a heredoc operator, and enqueues the herestring word $(cat as a fake delimiter. The fake header holds the queue head, the real delimiter line never matches, IFS_GLUE never splices, and the plan never sees the record — so no warning is produced at all.
  • Fix: one match arm in the header scan skips the unquoted <<< as a single three-byte token (+14/−0 in src/lexer/mod.rs), mirroring GNU's maximal-munch tokenization (parse.y read_token: <<+< is the single LESS_LESS_LESS token). The fake header is eliminated by construction; no second warning site.
  • Fail-first: 6 pins — exactly the 4 discriminating shapes red on pristine (warning absent), 2 guards green; 6/6 green after the fix, dual locale.
  • Oracle battery: 13 shapes vs cloud GNU 5.3.20, byte-compared per stream — 10 identical; the 3 diffs are recorded frontier, each proven pre-existing on pristine (redirect-word line seed, now tracked as [bug] heredoc EOF warning line attribution for compound-command redirect words uses the legacy seed #4197; dual-heredoc plan attribution, uniform with the command-word path; the while shape's existence+text match).
  • Sweeps: adjacent families 107/107; expanded sweep 137 targets 1047/0; lib 1314 pass with 1 red reproducing identically on pristine (sandbox file-mode artifact).
  • CI census differential: 12 FAIL names; beyond the 12-name baseline only issue4181_subshell_wait_retires_dead_coproc_vars — the rotator adjudicated 2026-11-25 (documented q2 EOF-before-death-record window ~1/30; 5/5 green on tree and pristine locally). Goldens red only on the standing [goldens] upstream_suite_slice_snapshots nondeterministic on Windows runner: comsub2/errors first-mismatch after comsub fix #4038 shape.

Net: src +14/−0, tests +132.

@caomengxuan666
caomengxuan666 merged commit d632875 into master Nov 25, 2026
10 of 12 checks passed
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