From 638378ca6d7d81fb762fb30c1ca31b0d4885a571 Mon Sep 17 00:00:00 2001 From: Jorres Tarasov Date: Thu, 23 May 2024 15:45:04 +0200 Subject: [PATCH] fix(ssh-args): space inside quotes --- pkg/options/options_suite_test.go | 12 ++++++++---- pkg/options/restart.go | 2 +- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/pkg/options/options_suite_test.go b/pkg/options/options_suite_test.go index 151b9d0..f059530 100644 --- a/pkg/options/options_suite_test.go +++ b/pkg/options/options_suite_test.go @@ -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 ubuntu@static-node-1.ydb-cluster.com\\\"", + []string{"ssh", "-i", "~/yandex", "-o", "ProxyCommand=\"ssh -W %h:%p -i ~/yandex ubuntu@static-node-1.ydb-cluster.com\""}, ), ) }) diff --git a/pkg/options/restart.go b/pkg/options/restart.go index 3682dd3..5ef4157 100644 --- a/pkg/options/restart.go +++ b/pkg/options/restart.go @@ -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)) }