Skip to content

Commit

Permalink
fix(ssh-args): space inside quotes
Browse files Browse the repository at this point in the history
  • Loading branch information
Jorres committed May 23, 2024
1 parent 4fb2872 commit 638378c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
12 changes: 8 additions & 4 deletions pkg/options/options_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,16 @@ var _ = Describe("Test parsing SSHArgs", func() {
[]string{"arg1", "arg2", "arg3"},
),
Entry("not split by whitespace inside quotes",
"arg1 arg2 ProxyCommand=\"cmd\"",
[]string{"arg1", "arg2", "ProxyCommand=\"cmd\""},
"arg1 arg2 ProxyCommand=\\\"arg1 arg2\\\"",
[]string{"arg1", "arg2", "ProxyCommand=\"arg1 arg2\""},
),
Entry("not split by comma",
"arg1,arg2 ProxyCommand=\"cmd\"",
[]string{"arg1,arg2", "ProxyCommand=\"cmd\""},
"arg1,arg2",
[]string{"arg1,arg2"},
),
Entry("real world example",
"ssh -i ~/yandex -o ProxyCommand=\\\"ssh -W %h:%p -i ~/yandex [email protected]\\\"",
[]string{"ssh", "-i", "~/yandex", "-o", "ProxyCommand=\"ssh -W %h:%p -i ~/yandex [email protected]\""},
),
)
})
2 changes: 1 addition & 1 deletion pkg/options/restart.go
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ func parseSSHArgs(rawArgs string) []string {
continue
}

if unicode.IsSpace(rawRunes[i]) {
if unicode.IsSpace(rawRunes[i]) && !isInsideQuotes {
if len(curArg) > 0 {
args = append(args, string(curArg))
}
Expand Down

0 comments on commit 638378c

Please sign in to comment.