fix: Avoid double escaping of ProxyCommand on Windows (#3664)

Fixes #2853
This commit is contained in:
Mathias Fredriksson
2022-08-24 19:12:40 +03:00
committed by GitHub
parent 09142255e6
commit 123fe0131e

View File

@ -280,10 +280,16 @@ func configSSH() *cobra.Command {
"\tLogLevel ERROR", "\tLogLevel ERROR",
) )
if !skipProxyCommand { if !skipProxyCommand {
// In SSH configs, strings inside "" are interpreted literally and there
// is no need to e.g. escape backslashes (common on Windows platforms).
// We will escape the quotes, though.
escapedBinaryFile := strings.ReplaceAll(binaryFile, "\"", "\\\"")
if !wireguard { if !wireguard {
configOptions = append(configOptions, fmt.Sprintf("\tProxyCommand %q --global-config %q ssh --stdio %s", binaryFile, root, hostname)) //nolint:gocritic // We don't want to use %q here, see above.
configOptions = append(configOptions, fmt.Sprintf("\tProxyCommand \"%s\" --global-config \"%s\" ssh --stdio %s", escapedBinaryFile, root, hostname))
} else { } else {
configOptions = append(configOptions, fmt.Sprintf("\tProxyCommand %q --global-config %q ssh --wireguard --stdio %s", binaryFile, root, hostname)) //nolint:gocritic // We don't want to use %q here, see above.
configOptions = append(configOptions, fmt.Sprintf("\tProxyCommand \"%s\" --global-config \"%s\" ssh --wireguard --stdio %s", escapedBinaryFile, root, hostname))
} }
} }