From f29992c0f14e27fec7dc3a7b7e84b83bdb1fae6f Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Tue, 27 Dec 2022 16:26:37 +0100 Subject: [PATCH] cli/command/network: use strings.Cut Signed-off-by: Sebastiaan van Stijn --- cli/command/network/connect.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/cli/command/network/connect.go b/cli/command/network/connect.go index ea4a7aa023..0c7552542d 100644 --- a/cli/command/network/connect.go +++ b/cli/command/network/connect.go @@ -81,13 +81,13 @@ func runConnect(dockerCli command.Cli, options connectOptions) error { func convertDriverOpt(opts []string) (map[string]string, error) { driverOpt := make(map[string]string) for _, opt := range opts { - parts := strings.SplitN(opt, "=", 2) - if len(parts) != 2 { + k, v, ok := strings.Cut(opt, "=") + // TODO(thaJeztah): we should probably not accept whitespace here (both for key and value). + k = strings.TrimSpace(k) + if !ok || k == "" { return nil, fmt.Errorf("invalid key/value pair format in driver options") } - key := strings.TrimSpace(parts[0]) - value := strings.TrimSpace(parts[1]) - driverOpt[key] = value + driverOpt[k] = strings.TrimSpace(v) } return driverOpt, nil }