mirror of
https://github.com/Luzifer/go_helpers.git
synced 2024-12-25 05:21:20 +00:00
Fix: Do not panic on weird env list entries
Signed-off-by: Knut Ahlers <knut@ahlers.me>
This commit is contained in:
parent
76c41f9c37
commit
82b334b3d3
2 changed files with 6 additions and 2 deletions
4
env/env.go
vendored
4
env/env.go
vendored
|
@ -11,6 +11,10 @@ func ListToMap(list []string) map[string]string {
|
|||
}
|
||||
|
||||
parts := strings.SplitN(entry, "=", 2)
|
||||
if len(parts) == 1 {
|
||||
// No value, set to empty string
|
||||
parts = append(parts, "")
|
||||
}
|
||||
out[parts[0]] = strings.Trim(parts[1], "\"")
|
||||
}
|
||||
return out
|
||||
|
|
4
env/env_test.go
vendored
4
env/env_test.go
vendored
|
@ -10,19 +10,20 @@ import (
|
|||
)
|
||||
|
||||
var _ = Describe("Env", func() {
|
||||
|
||||
Context("ListToMap", func() {
|
||||
var (
|
||||
list = []string{
|
||||
"FIRST_KEY=firstvalue",
|
||||
"SECOND_KEY=secondvalue",
|
||||
"WEIRD=",
|
||||
"NOVALUE",
|
||||
"",
|
||||
}
|
||||
emap = map[string]string{
|
||||
"FIRST_KEY": "firstvalue",
|
||||
"SECOND_KEY": "secondvalue",
|
||||
"WEIRD": "",
|
||||
"NOVALUE": "",
|
||||
}
|
||||
)
|
||||
|
||||
|
@ -51,5 +52,4 @@ var _ = Describe("Env", func() {
|
|||
Expect(l).To(Equal(list))
|
||||
})
|
||||
})
|
||||
|
||||
})
|
||||
|
|
Loading…
Reference in a new issue