Repository navigation
Description
Summary
Two stderr-only diagnostic gaps uncovered when running heredoc3.sub and heredoc7.sub against WSL GNU Bash 5.3.0. These do not affect stdout (the harness diff is 0 for heredoc suite), only stderr diagnostics.
heredoc7.sub — warning line number
GNU:
./heredoc7.sub: line 29: warning: here-document at line 29 delimited by end-of-file (wanted `EOF')
rubash:
./heredoc7.sub: line 26: warning: here-document at line 26 delimited by end-of-file (wanted `EOF')
Root cause
cat <<EOF && grep $( on line 26 opens a heredoc, but the body (foobar, EOF) is swallowed by the command substitution $(. When the ) closes on line 29, GNU make_cmd.c:627 reports the heredoc start as the closing-paren line (29), not the <<EOF line (26).
In rubash, report_unterminated_heredoc (src/executor/public_accessors.rs:605) computes warning_line = start_line + body_lines, but cmd.heredoc only contains the \x1f sentinel (body was consumed by comsub), so body_lines = 0 and warning_line = start_line = 26.
Fix direction
When a heredoc spans a command-substitution boundary, the warning line should be the comsub closing line, not the <<EOF line. This requires the executor to track the comsub close line and pass it to report_unterminated_heredoc, or to store the actual body line count in cmd.heredoc even when the body was consumed by comsub.
heredoc3.sub — syntax error message
GNU:
./heredoc3.sub: line 99: syntax error: unexpected end of file from `(' command on line 96
rubash:
./heredoc3.sub: line 92: syntax error near unexpected end of file
Root cause
The final (cat <<EOF\nstill more text\nEOF) (lines 96-98) is an unterminated subshell heredoc. rubash has report_unterminated_subshell_heredoc (src/executor/public_accessors.rs:630) that produces the correct GNU-format message, but this case falls through to the generic parse_loop.rs error path instead.
Fix direction
The parser needs to recognize (cat <<EOF ... EOF) as an unterminated subshell heredoc and route to report_unterminated_subshell_heredoc instead of the generic EOF error.
heredoc3.sub — 5 warnings (GNU over-reporting, NOT a rubash bug)
GNU emits 5 here-document at line N delimited by end-of-file warnings for $(cat <<EOF\n...\nEOF) patterns where EOF) is on the same line. These are GNU over-warnings — rubash correctly handles EOF) on the same line without warning. Matching GNU here would mean intentionally emitting false positives, which is wrong. These 5 warnings should NOT be "fixed".
Verification
# GNU
MSYS_NO_PATHCONV=1 wsl bash /mnt/d/repo/rubash-audit/scripts/true-baseline-audit.sh heredoc
# Both produce identical stdout; only stderr differsGenerated with Devin
Activity
release v1.1.0: CTLESC leak fix, heredoc diagnostics, warning suppres…
caomengxuan666 commentedon Sep 17, 2026
Fixed in 7476764.
heredoc7.sub — GNU semantics:
make_here_documentreceives the parser'sline_numberatgather_here_documentstime (parse.y:3130), i.e. the physical line where the logical command ended — when the body was swallowed by$(, that's the)line (29), not the<<line (26). HereDocBody tokens now carry this gather line (HereDocRedirect::gather_line→CommandNode::heredoc_gather_line), and all three warning reporters use it. Output now byte-identical:line 29: warning: here-document at line 29 delimited by end-of-file (wanted \EOF')`.heredoc3.sub — the unclosed
(now takes the GNU yyerror EOF path (parse.y:6890-6901, compoundcmd_lineno stack): pending-heredoc warnings are recovered by pairing<<delimiters with their body tokens in the failed region, thenline 99: syntax error: unexpected end of file from \(' command on line 96`. Both lines now byte-identical to GNU.Verified: 21/21 stderr + 25/25 stdout probes vs WSL GNU 5.3.0; head-vs-mine zero regressions on heredoc/alias/redir/comsub/func/varenv/errors/parser.
Not covered (separate issues):
-cexecutes earlier commands before the parse error (GNU parses the whole-cstring atomically — architectural difference);/usr/bin/grep-style argv0 prefixes;x*filename errors are WinuxCmd Windows-filename limits.fix(heredoc): report gather-line and unclosed-( EOF diagnostics like GNU