Fix `index out of range [1] with length 1` error on env2map (#1463)

This happened only when helmfile is run in an environment that any environment variable definition does not include `=` and the right side.
This commit is contained in:
Yusuke Kuoka 2020-09-08 11:23:36 +09:00 committed by GitHub
parent 9d2c0d4285
commit 0482ba3b6f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 10 additions and 1 deletions

View File

@ -107,7 +107,16 @@ func env2map(env []string) map[string]string {
wanted := map[string]string{}
for _, cur := range env {
pair := strings.SplitN(cur, "=", 2)
wanted[pair[0]] = pair[1]
var v string
// An environment can completely miss `=` and the right side.
// If we didn't deal with that, this may fail due to an index-out-of-range error
if len(pair) > 1 {
v = pair[1]
}
wanted[pair[0]] = v
}
return wanted
}