Skip to content

fix: join continued source lines without empty words - #243

Merged
pgrayy merged 2 commits into
strands-agents:mainfrom
pgrayy:fix/pgrayy/shell-line-continuations
Nov 11, 2026
Merged

pgrayy merged 2 commits into
strands-agents:mainfrom
pgrayy:fix/pgrayy/shell-line-continuations

Conversation

@pgrayy

@pgrayy pgrayy commented Nov 11, 2026 •

Copy link
Copy Markdown
Member

Description

Backslash-newline continuations can execute a command before its next physical line is read. Removing a continuation can also introduce an empty argument or reject valid grouped commands.

For example, this is one command written across two physical lines:

printf '<%s>\n' first \
  second

Before the fix, the shell prints <first> and <>, then tries to run second as a separate command and exits with status 127. After the fix, it prints:

<first>
<second>

The command exits with status 0 and no error.

The source executor tells the shared parser whether more physical lines remain. The lexer uses that context to defer a trailing escape and omits words emptied by continuation removal. The lexer retains explicitly quoted empty words as tokens and preserves the existing end-of-input escape handling. Alias expansion uses a bounded cursor adjustment when replacements remove tokens.

Some quoted empty arguments are still lost during execution. Continuations inside operators or variable names remain outside this fix.

Related Issues

Companion to strands-agents/box#402, which applies the same fix to Box's vendored Shell. This PR uses upstream's existing string errors and the same three regression tests.

Documentation PR

No separate documentation PR is needed for this bug fix. Parser doc comments explain the new input flag, and the example above shows the behavior change.

Type of Change

Bug fix

Testing

Validated on macOS against def7ab7:

  • All three new regression tests fail without the fix and pass with it. They cover direct execution, sourced files, sh scripts, argument boundaries, quoting, heredocs, aliases, and a continuation at end of input. The empty-alias case fails if the cursor fix is removed.
  • cargo test --locked --workspace --all-targets: 2,130 passed, no failures or ignored tests.
  • cargo test --locked --workspace --doc: 16 passed; one existing macro example is ignored.
  • cargo test --locked --lib --features node: 64 passed.
  • cargo fmt --all -- --check and cargo clippy --locked --workspace --all-targets: passed; warning diagnostics match the pre-fix baseline.
  • RUSTDOCFLAGS='-D warnings' cargo doc --locked --workspace --no-deps and cargo build --locked --no-default-features: passed.
  • The CLI example above produces the expected output and status, matching Bash.

Python and JavaScript binding suites, WASM, Linux, and Windows were not run locally. No binding code changed.

  • I ran the relevant test suites for the bindings I touched (cargo test --workspace --all-targets, pytest tests/python, npm test)
  • If I touched Rust, I ran cargo fmt and cargo clippy

Checklist

  • I have read the CONTRIBUTING document
  • I have reviewed and understand every line of code in this PR, including any generated by AI tools, and I can explain why it works
  • My change is focused and reasonably small; I have split unrelated work into separate PRs
  • I have added any necessary tests that prove my fix is effective or my feature works
  • I have updated the documentation accordingly
  • I have added an appropriate example to the documentation to outline the feature, or no new docs are needed
  • My changes generate no new warnings
  • Any dependent changes have been merged and published

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@pgrayy
pgrayy marked this pull request as ready for review November 11, 2026 17:47
@pgrayy
pgrayy requested a review from a team as a code owner November 11, 2026 17:47
zastrowm
zastrowm previously approved these changes Nov 11, 2026
@pgrayy
pgrayy merged commit e43d8a7 into strands-agents:main Nov 11, 2026
31 checks passed
@pgrayy
pgrayy deleted the fix/pgrayy/shell-line-continuations branch November 11, 2026 19:57
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.

2 participants