You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
parser: heredoc + pipeline inside a quoted "$( ... )" fails to parse #703
A heredoc that feeds a pipeline, inside a double-quoted command substitution, fails to parse.
Environment: Niubash 1.4.0 · rubash git e785c3c8f610 — Windows 10 x64. Method: differential vs GNU bash 5.2.21(1) / 5.3.0. The probe file is LF-only, so this is not a CRLF artifact.
Repro
$ echo"X=$(cat <<EOF | catbodyEOF)"
niu :command substitution: line 4: unexpected EOF while looking for matching `)' (exit 1, no output)bash: X=body
Version note (correction to the Method line): the oracle was reached with bare wsl.exe -e bash, which resolves through PATH to /usr/local/bin/bash = GNU bash 5.3.0(1) — not 5.2.21. The 5.2.21 build lives at /bin/bash, and every item in this report was re-checked on it as well; results were identical on both.
So the two versions are listed in the wrong order above: 5.3.0 was the default, 5.2.21 the cross-check.
No finding here changes; noting it only so the numbers reproduce. (Incidentally 5.3.0 is also the oracle cited in rubash#641, "the repository oracle is WSL 5.3.0".)
Root cause was not line accounting but the delimiter WORD. The word-expansion comsub collector (collect_command_substitution_source_ex, src/executor/embedded_mutations.rs) scanned the heredoc delimiter to end of line, so cat <<EOF | cat declared the delimiter EOF | cat. The EOF terminator line then never matched, the collector swallowed the rest of the script looking for it, and the unclosed ) surfaced as the unexpected EOF fatal. The three shapes the report lists as working all hand the collector a header line with nothing after the delimiter word, which is why only quoted + heredoc + pipeline went red.
The delimiter word now ends at the first unquoted blank or shell metacharacter (;|&()<>), the rule read_token_word already applies (parse.y:5688 shellbreak) and the rule the lexer's own heredoc header scan already implements (lexer/heredoc_scan.rs skip_heredoc_in_chars_core). << immediately followed by - is one operator word carrying the tab-strip dash, and blanks between << and the word are skipped: cat << EOF names EOF, cat << -EOF names -EOF without stripping, same as GNU.
Fixing the scan exposed a second defect on the EOF) pushback shape (x=$(cat <<EOF | cat + body + EOF)): the substitution output carried a stray EOF line. The lexer marks a heredoc whose ) closes on the delimiter line by splicing an IFS_GLUE byte before that ) (make_cmd.c:602-611 shape); the typed fast path consumes that signal, but the marker also reached the real parser, where the terminator line read EOF\x1c and stopped matching its delimiter. The marker is now stripped after the typed path and before every real-parser path.
Pinned in mod issue_703 (tests/regression.rs) per #746: 703.1 the exact repro [ratchet], 703.2 the three already-working shapes [control], 703.3 the EOF) pushback shape [ratchet], 703.4 the delimiter spellings << EOF / <<-EOF / <<"E O" [ratchet], 703.5 a ; after the delimiter word [ratchet]. Reverting the collector fix turns 4 of the 5 red; the survivor is the 703.2 control.
One gap deliberately left: bash's own behaviour for << -WORD inside a command substitution is self-contradictory (single blank strips, double blank treats the dash as text, and the reported EOF line depends on the terminator line), so there is no oracle to match. rubash stays consistent with its own lexer rules and with bash's top-level behaviour.
The same-rule-twice drift behind this bug is recorded in docs/pitfall-taxonomy-and-governance.md (S4 row plus structural conclusion 5): the lexer scan and the comsub collector each carried their own copy of the delimiter word-boundary rule, and the copies had drifted.
Activity
caomengxuan666 commentedon Oct 17, 2026
Version note (correction to the Method line): the oracle was reached with bare
wsl.exe -e bash, which resolves through PATH to/usr/local/bin/bash= GNU bash 5.3.0(1) — not 5.2.21. The 5.2.21 build lives at/bin/bash, and every item in this report was re-checked on it as well; results were identical on both.So the two versions are listed in the wrong order above: 5.3.0 was the default, 5.2.21 the cross-check.
No finding here changes; noting it only so the numbers reproduce. (Incidentally 5.3.0 is also the oracle cited in rubash#641, "the repository oracle is WSL 5.3.0".)
fix(comsub): heredoc delimiter word ends at the first unquoted blank (#…
caomengxuan666 commentedon Oct 18, 2026
Fixed in 041f0a6.
Root cause was not line accounting but the delimiter WORD. The word-expansion comsub collector (
collect_command_substitution_source_ex, src/executor/embedded_mutations.rs) scanned the heredoc delimiter to end of line, socat <<EOF | catdeclared the delimiterEOF | cat. TheEOFterminator line then never matched, the collector swallowed the rest of the script looking for it, and the unclosed)surfaced as theunexpected EOFfatal. The three shapes the report lists as working all hand the collector a header line with nothing after the delimiter word, which is why only quoted + heredoc + pipeline went red.The delimiter word now ends at the first unquoted blank or shell metacharacter (
;|&()<>), the rule read_token_word already applies (parse.y:5688 shellbreak) and the rule the lexer's own heredoc header scan already implements (lexer/heredoc_scan.rs skip_heredoc_in_chars_core).<<immediately followed by-is one operator word carrying the tab-strip dash, and blanks between<<and the word are skipped:cat << EOFnamesEOF,cat << -EOFnames-EOFwithout stripping, same as GNU.Fixing the scan exposed a second defect on the
EOF)pushback shape (x=$(cat <<EOF | cat+body+EOF)): the substitution output carried a strayEOFline. The lexer marks a heredoc whose)closes on the delimiter line by splicing an IFS_GLUE byte before that)(make_cmd.c:602-611 shape); the typed fast path consumes that signal, but the marker also reached the real parser, where the terminator line readEOF\x1cand stopped matching its delimiter. The marker is now stripped after the typed path and before every real-parser path.Pinned in
mod issue_703(tests/regression.rs) per #746: 703.1 the exact repro [ratchet], 703.2 the three already-working shapes [control], 703.3 theEOF)pushback shape [ratchet], 703.4 the delimiter spellings<< EOF/<<-EOF/<<"E O"[ratchet], 703.5 a;after the delimiter word [ratchet]. Reverting the collector fix turns 4 of the 5 red; the survivor is the 703.2 control.One gap deliberately left: bash's own behaviour for
<< -WORDinside a command substitution is self-contradictory (single blank strips, double blank treats the dash as text, and the reported EOF line depends on the terminator line), so there is no oracle to match. rubash stays consistent with its own lexer rules and with bash's top-level behaviour.The same-rule-twice drift behind this bug is recorded in docs/pitfall-taxonomy-and-governance.md (S4 row plus structural conclusion 5): the lexer scan and the comsub collector each carried their own copy of the delimiter word-boundary rule, and the copies had drifted.