Skip to content

fix(parser): handle heredoc pipe ordering and edge cases#379

Merged
chaliy merged 1 commit intomainfrom
claude/fix-359-heredoc-edge-cases-Vvs93
Feb 27, 2026
Merged

fix(parser): handle heredoc pipe ordering and edge cases#379
chaliy merged 1 commit intomainfrom
claude/fix-359-heredoc-edge-cases-Vvs93

Conversation

@chaliy
Copy link
Copy Markdown
Contributor

@chaliy chaliy commented Feb 27, 2026

Summary

  • Fix heredoc pipe ordering: cat <<EOF | sort now correctly pipes heredoc content to the next command in the pipeline
  • Fix pipe continuation: cat <<EOF |\nsort works via rest-of-line re-injection
  • Handle partial quote delimiters: <<'EOF'"2" correctly combines to delimiter EOF2 with quoting preventing expansion
  • Fix multiple heredocs on one line: while cat <<E1 && cat <<E2; do ... done parses and executes correctly
  • Fix heredoc followed by multiline dquote: cat <<EOF; echo "two\nthree" handles quoted strings spanning lines
  • Capture while/until condition stdout so heredocs in loop conditions produce visible output

All 6 previously-skipped heredoc-edge spec tests are now enabled and passing.

Approach

Lexer: Added a VecDeque<char> re-injection buffer. read_heredoc saves the rest of the command line (after the heredoc delimiter token) instead of discarding it, then re-injects it after reading the heredoc body. peek_char/advance check the buffer first.

Lexer: read_continuation_into concatenates adjacent quoted/unquoted segments after a single-quoted string, enabling partial-quote heredoc delimiters.

Interpreter: execute_while and execute_until now capture and emit condition command stdout/stderr.

Test plan

  • All 6 heredoc-edge skipped tests enabled and passing
  • 2 new parser unit tests (heredoc pipe, multiple heredocs)
  • Full spec test suite passes (1305 tests, 1192 passed, 0 failed, 113 skipped)
  • bash_comparison_tests pass (identical output to real bash)
  • All 1017 lib unit tests pass
  • cargo fmt --check clean
  • No new clippy warnings (pre-existing resolve_redirect_url dead_code only)

Closes #359

@chaliy chaliy force-pushed the claude/fix-359-heredoc-edge-cases-Vvs93 branch from bcfc0fd to d50c0cf Compare February 27, 2026 23:14
- Lexer saves rest-of-line after heredoc delimiter and re-injects it via
  a VecDeque buffer, so `cat <<EOF | sort` correctly pipes heredoc content
- Pipe continuation (`cat <<EOF |\nsort`) also works via the same mechanism
- Quote-aware rest-of-line scanning handles `cat <<EOF; echo "two\nthree"`
  where double-quoted strings span physical lines
- read_continuation_into concatenates adjacent quoted/unquoted segments
  after single-quoted strings, enabling partial-quote delimiters like
  `<<'EOF'"2"` -> delimiter `EOF2`
- Multiple heredocs on one line work naturally via repeated rest-of-line
  save/reinject (e.g., `while cat <<E1 && cat <<E2; do ... done`)
- While/until condition stdout is now captured and emitted, fixing
  `while cat <<EOF; do ... done` producing no condition output

Enables all 6 previously-skipped heredoc-edge spec tests.

Closes #359
@chaliy chaliy force-pushed the claude/fix-359-heredoc-edge-cases-Vvs93 branch from d50c0cf to 7acf973 Compare February 27, 2026 23:39
@chaliy chaliy merged commit d8782b3 into main Feb 27, 2026
16 checks passed
@chaliy chaliy deleted the claude/fix-359-heredoc-edge-cases-Vvs93 branch March 12, 2026 03:43
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.

Heredoc edge cases: multiple heredocs, pipe ordering, partial quote delimiters

2 participants