Skip to content

collapse_line_continuations fuses commands when the backslash before a newline is escaped (\\<newline>) #3190

Open

Description

@falsydotdev

Summary

collapse_line_continuations (src/discover/registry.rs, LINE_CONTINUATION_RE) treats every \<newline> as a bash line continuation. But when the backslash is itself escaped — \\<newline> — bash sees a literal backslash followed by a command separator: two independent commands. The regex matches the second backslash + newline and collapses them to a space, fusing the two commands into one before rewriting.

Reproduction (rtk 0.43.0 and develop)

Input (literal \\ then newline):

git add path\\
git status

Bash runs two commands: git add 'path\' then git status (verify: printf one\\ ; printf two split across lines prints [one\][two]).

rtk rewrite / the hook instead produce:

rtk git add path\ git status

— one fused command with an rtk prefix, where bash saw a command boundary. git status is silently consumed as arguments to git add.

Suggested fix

Make the continuation regex require an odd number of preceding backslashes (an even count means the final backslash is escaped/literal and the newline is a real separator).

Found while adversarially testing #3188 (which does not touch this code path; the collapse runs before the multi-line handling added there).

Activity

  1. pszymkowiak commented on Jul 24, 2026

    @pszymkowiak
    Collaborator

    wshm · Automated triage by AI

    🔍 Automated Triage

    🐛 Category bug
    🟠 Priority high
    🎯 Confidence 92%

    Summary

    collapse_line_continuations incorrectly treats an escaped backslash (\) as a bash line continuation, silently fusing two independent commands (e.g. git status becomes an argument to git add); fix regex in src/discover/registry.rs (LINE_CONTINUATION_RE) to require an odd count of preceding backslashes.

    This looks like a simple fix that could be auto-resolved. Repo maintainers can use /wshm fix to attempt it.

    📁 Relevant files
    • src/discover/registry.rs

    Triaged automatically by wshm · This is an automated analysis, not a human review.

  2. nightcityblade commented on Jul 24, 2026

    @nightcityblade

    Hi, I'd like to work on this. I'll submit a PR shortly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:clibugpriority:high

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions