From b3557b2840b35701779639f2455794ca2d6e02fa Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Tue, 27 Dec 2022 16:28:31 +0100 Subject: [PATCH] cli/command/stack: use strings.Cut Signed-off-by: Sebastiaan van Stijn --- cli/command/stack/loader/loader.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/cli/command/stack/loader/loader.go b/cli/command/stack/loader/loader.go index 22352f434e..105e84e644 100644 --- a/cli/command/stack/loader/loader.go +++ b/cli/command/stack/loader/loader.go @@ -104,12 +104,12 @@ func GetConfigDetails(composefiles []string, stdin io.Reader) (composetypes.Conf func buildEnvironment(env []string) (map[string]string, error) { result := make(map[string]string, len(env)) for _, s := range env { - // if value is empty, s is like "K=", not "K". - if !strings.Contains(s, "=") { + k, v, ok := strings.Cut(s, "=") + if !ok || k == "" { return result, errors.Errorf("unexpected environment %q", s) } - kv := strings.SplitN(s, "=", 2) - result[kv[0]] = kv[1] + // value may be set, but empty if "s" is like "K=", not "K". + result[k] = v } return result, nil }