Repository navigation
fix(shell): join continued source lines without empty words - #402
Conversation
## Problem A source statement ending in an unquoted backslash ran before the next physical line was read. Removing a backslash-newline could also emit an empty word, which added arguments and broke the grouped condition in nvm 0.41.0. ## Solution Pass physical-line availability from the source executor to the shared parser. The lexer marks an unfinished escape as incomplete only while more input remains. Omit words with no parts after continuation removal, and bound the alias cursor adjustment when replacements remove words. End-of-input escape handling and explicitly quoted empty arguments keep their behavior. No public interface, dependency, policy, or limit changes. Record the upstream bug and remaining limitations in UPSTREAM.md. ## Tests line_continuations_join_source_lines checks command and argument joining, pipeline input, and short-circuit evaluation through direct execution, dot-source, and sh. line_continuations_do_not_create_words checks exact arguments, the reduced nvm condition, and quoted empty arguments. line_continuations_preserve_quoting_and_input_boundaries checks quotes, escaped backslashes, comments, heredoc sequencing, EOF, and empty aliases. All three fail before the fix. Separate mutations of source accumulation, empty-word removal, and alias bounds each fail their regression. All 2,002 shell tests pass with all features, including doctests. The three ignored child-helper tests are invoked by their parent tests. All-features build, no-default-features build, formatting, and all-targets/all-features clippy pass. The 14 vendored clippy diagnostics match the baseline. All 24 exploratory scripts match Bash status and stdout. An optimized build sources nvm 0.41.0 with --no-use and prints its version. scripts/test-all.sh box-examples builds Box and containment with all features, then reports that no scripted examples remain. Deterministic containment is GREEN: 129 pass, 12 declared Linux-only skips on macOS, zero failures or errors, and full expected coverage across 141 cases. Independent feature review found no remaining issues. Full workspace tests, live tutorial, and other platforms were not run. Default nvm initialization still fails due to the pre-existing loss of quoted empty parameter arguments, reproduced without continuations in both builds. Large statements still incur repeated parsing, and separate lexer collectors still mishandle continuations within operators or variable names.
|
Assessment: Comment The core fix is correct. I probed about 40 continuation scripts against the base and Bash, and every row in the main path improved or stayed the same. The one open finding, posted inline, is about end-of-input Review Categories
The regression tests are well chosen, and the alias underflow fix was a good catch. |
|
Assessment: Approve Re-reviewed at 974d4c1. The only change since e64c752 is in tests and docs, and it addresses the earlier finding.
|
|
Assessment: Approve Re-reviewed at eed0f0b. This is a merge of
|
|
Assessment: Approve Re-reviewed at d3628cc. This is a merge of
|
…5740518 already joins continued lines
Description
Backslash-newline continuations could make a command run before its next physical line was read. Removing a continuation could also create an unintended empty argument or break grouped syntax.
For example, this is one
printfcommand written across two physical lines:Before the fix: Strands Shell executed the first line too early, with
firstand an accidental empty argument. It printed:It then treated
secondas a separate command, reportedstrands-shell: second: command not found, and returned exit status 127.After the fix: Strands Shell collects the continued line and runs the command once with the two intended values,
firstandsecond. This is equivalent toprintf '<%s>\n' first second:It returns exit status 0 with no error. The example demonstrates both corrections: waiting for the continued line and avoiding an unintended empty argument.
The source executor now tells the shared parser when more physical lines remain. The lexer waits for a continued line and omits words with no parts. The lexer retains explicitly quoted empty words as tokens and preserves the existing end-of-input escape handling. Alias expansion bounds its cursor adjustment when replacements remove words.
Related Issues
Companion upstream fix: strands-agents/shell#243.
Reproduced from a user report; no linked issue.
Type of Change
Bug fix
Testing
source nvm.sh --no-use && nvm --versionsucceeds and prints0.41.0.main: 2,005 passed, zero failed, three existing ignored child-helper tests exercised by their parents. No interpreter-dependent skips.scripts/test-all.sh box-examplesbuilt Box and containment with all features. It reports an explicit skip because no scripted examples remain.Some quoted empty arguments are still lost during execution, including literal empty double quotes and empty expansions of unset parameters. This pre-existing defect also affects ordinary nvm initialization and was reproduced without continuations. Repeated parsing of large statements, and continuations inside operator or variable-name tokens, remain outside this fix.
Full workspace Rust tests and the live tutorial were not run locally. Local verification was on macOS. The change is confined to the vendored Shell parser/executor and touches no platform-specific code.
Checklist
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.