Skip to content

connect: pass post--- argv verbatim, don't re-split (#369) - #377

Merged
scttfrdmn merged 1 commit into
mainfrom
fix/369-connect-argv-resplit
Jul 19, 2026
Merged

scttfrdmn merged 1 commit into
mainfrom
fix/369-connect-argv-resplit

Conversation

@scttfrdmn

Copy link
Copy Markdown
Contributor

Fixes #369.

Bug

spawn connect <id> -- bash -lc "echo a && echo b" failed with bash: -c: option requires an argument. The one-shot handler space-joined the post--- argv into a single string and re-wrapped it in bash -c '...', so the 3-token argv [bash, -lc, "echo a && echo b"] became the remote string bash -c 'bash -lc echo a && echo b' — double-shelled and re-split, so -lc lost its script argument.

Fix

Shell-quote each post--- token individually and join with spaces (shellQuoteArgs), then pass it through verbatim — exactly what plain ssh host <argv...> does (ssh space-joins its command args and the remote login shell parses the result). The extra bash -c wrapper is dropped (redundant and lossy). So -- bash -lc "echo a && echo b" now reaches the remote as 'bash' '-lc' 'echo a && echo b' and runs correctly.

Test

TestShellQuoteArgs covers the #369 repro, embedded single quotes ('\'' escaping), and a pipeline preserved as one argument. go build ./..., cmd tests, gofmt clean.

`spawn connect <id> -- bash -lc "<script>"` mangled any multi-token command: the
argv was space-joined into one string and wrapped in `bash -c '...'`, so
`-- bash -lc "echo a && echo b"` became `bash -c 'bash -lc echo a && echo b'` and
bash's -c got no argument.

Shell-quote each post-`--` token individually and join, reproducing plain
`ssh host <argv...>` semantics (ssh space-joins the command args and the remote
login shell parses them). Drops the redundant/lossy extra bash -c wrapper.

Test: TestShellQuoteArgs covers the repro plus embedded quotes and pipelines.
@codecov

codecov Bot commented Jul 19, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 85.71429% with 1 line in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
cmd/connect.go 85.71% 1 Missing ⚠️

📢 Thoughts on this report? Let us know!

@scttfrdmn
scttfrdmn merged commit fb64234 into main Jul 19, 2026
7 checks passed
@scttfrdmn
scttfrdmn deleted the fix/369-connect-argv-resplit branch July 19, 2026 01:42
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.

connect: '-- bash -lc "<cmd>"' mangles multi-token commands (argv re-split)

1 participant