fix(parser): honor backslash-newline line continuations in here-documents - #3
Merged
Merged
Conversation
…ents In a here-document whose delimiter is unquoted, bash removes a backslash-newline pair outright and joins the two lines; a backslash is only literal there when it precedes `$`, a backtick, or another backslash. `heredoc_escape_sequence` covered those three characters but not newline, so the pair fell through to `heredoc_literal_text` and both the backslash and the newline were emitted verbatim. Add an explicit line-continuation rule and exclude it from the literal text rule. A quoted delimiter suppresses expansion entirely, so that path is untouched and continues to preserve the backslash, matching bash. Before: After (and bash): $ cat <<EOF $ cat <<EOF > alpha \ > alpha \ > beta > beta > EOF > EOF alpha \ alpha beta beta Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
cataggar
added a commit
that referenced
this pull request
Aug 22, 2026
…ents (#3) In a here-document whose delimiter is unquoted, bash removes a backslash-newline pair outright and joins the two lines; a backslash is only literal there when it precedes `$`, a backtick, or another backslash. `heredoc_escape_sequence` covered those three characters but not newline, so the pair fell through to `heredoc_literal_text` and both the backslash and the newline were emitted verbatim. Add an explicit line-continuation rule and exclude it from the literal text rule. A quoted delimiter suppresses expansion entirely, so that path is untouched and continues to preserve the backslash, matching bash. Before: After (and bash): $ cat <<EOF $ cat <<EOF > alpha \ > alpha \ > beta > beta > EOF > EOF alpha \ alpha beta beta Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Second defect found while running an 88k-line bash CLI (
kenji-cli) under brush; surfaced as a diff in one subcommand's--helpoutput.Root cause
In a here-document whose delimiter is unquoted, bash removes a backslash-newline pair outright and joins the two lines. A backslash is only literal there when it precedes
$, a backtick, or another backslash.heredoc_escape_sequencecovered those three characters but not newline, so the pair fell through toheredoc_literal_textand both the backslash and the newline were emitted verbatim.alpha betaalpha \/betaFix
Add an explicit line-continuation rule and exclude it from the literal text rule. A quoted delimiter suppresses expansion entirely, so that path is untouched and continues to preserve the backslash — matching bash.
Testing
\$/\`/\\/ continuation togetherbrush-parser: 224/224 unit tests passcargo clippyandcargo fmt --checkclean