Repository navigation
connect: pass post--- argv verbatim, don't re-split (#369) - #377
Merged
Merged
Conversation
`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 Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
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.
Fixes #369.
Bug
spawn connect <id> -- bash -lc "echo a && echo b"failed withbash: -c: option requires an argument. The one-shot handler space-joined the post---argv into a single string and re-wrapped it inbash -c '...', so the 3-token argv[bash, -lc, "echo a && echo b"]became the remote stringbash -c 'bash -lc echo a && echo b'— double-shelled and re-split, so-lclost its script argument.Fix
Shell-quote each post-
--token individually and join with spaces (shellQuoteArgs), then pass it through verbatim — exactly what plainssh host <argv...>does (ssh space-joins its command args and the remote login shell parses the result). The extrabash -cwrapper 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
TestShellQuoteArgscovers the #369 repro, embedded single quotes ('\''escaping), and a pipeline preserved as one argument.go build ./...,cmdtests, gofmt clean.