Skip to content

fix(interpreter): write heredoc content when redirected to file#370

Merged
chaliy merged 2 commits intomainfrom
claude/fix-345-heredoc-redirect-TjcEQ
Feb 27, 2026
Merged

fix(interpreter): write heredoc content when redirected to file#370
chaliy merged 2 commits intomainfrom
claude/fix-345-heredoc-redirect-TjcEQ

Conversation

@chaliy
Copy link
Contributor

@chaliy chaliy commented Feb 27, 2026

Summary

  • Fix heredoc redirect to file (cat <<EOF > file) which previously wrote to stdout instead of the file
  • Lexer now captures rest-of-line text after heredoc delimiter instead of discarding it
  • Parser creates a sub-parser to extract additional redirects from the rest-of-line

Closes #345

Test plan

  • Added 3 new spec tests: heredoc_redirect_after, heredoc_redirect_after_with_vars, heredoc_redirect_after_multiline
  • Added lexer unit test test_read_heredoc_with_redirect
  • All 1308 bash spec tests pass (100% pass rate)
  • Existing heredoc_to_file test (cat > file <<EOF syntax) still passes
  • cargo fmt --check clean
  • cargo clippy -- -D warnings clean

Closes #345

The parser's heredoc handling broke out of the simple-command loop
immediately after consuming the heredoc body, which discarded any
tokens on the same line after the delimiter (e.g. `> file` in
`cat <<EOF > file`). The lexer also skipped the rest-of-line text.

Fix: the lexer now saves the rest-of-line text after the heredoc
delimiter into `heredoc_rest_of_line`. The parser reads this field,
creates a sub-parser to extract additional redirects, and adds them
to the command's redirect list before breaking.

https://claude.ai/code/session_018RLVEEcJBFYsxQKT5wYyNu
…parsing

The sub-parser approach using parse_simple_command() returned None for
redirect-only input (e.g. ` > file` with no command word), silently
dropping the output redirect. Parse redirect tokens directly from the
rest-of-line instead.

Also change heredoc_redirect_after_multiline test to use /tmp/app/
instead of /etc/app/ which requires root in CI.

https://claude.ai/code/session_01QbjrsMFJbHy5XfHCzA6TjM
@chaliy chaliy force-pushed the claude/fix-345-heredoc-redirect-TjcEQ branch from e619123 to e8dc217 Compare February 27, 2026 23:14
@chaliy chaliy merged commit 3cca974 into main Feb 27, 2026
16 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.

bug: heredoc redirect to file does not write content (cat <<EOF > file)

2 participants