Skip to content

Commit

Permalink
Environment variables may not have a value, currently env.Map blows u…
Browse files Browse the repository at this point in the history
…p as it's expecting this to always be the case
  • Loading branch information
stevenjack committed Sep 21, 2017
1 parent 98edf3e commit cd1c311
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
6 changes: 5 additions & 1 deletion env.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,11 @@ func (env *Env) Map() map[string]string {
m := make(map[string]string)
for _, kv := range *env {
parts := strings.SplitN(kv, "=", 2)
m[parts[0]] = parts[1]
if len(parts) == 1 {
m[parts[0]] = ""
} else {
m[parts[0]] = parts[1]
}
}
return m
}
1 change: 1 addition & 0 deletions env_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,7 @@ func TestMap(t *testing.T) {
expected map[string]string
}{
{[]string{"PATH=/usr/bin:/bin", "PYTHONPATH=/usr/local"}, map[string]string{"PATH": "/usr/bin:/bin", "PYTHONPATH": "/usr/local"}},
{[]string{"ENABLE_LOGGING", "PYTHONPATH=/usr/local"}, map[string]string{"ENABLE_LOGGING": "", "PYTHONPATH": "/usr/local"}},
{nil, nil},
}
for _, tt := range tests {
Expand Down

0 comments on commit cd1c311

Please sign in to comment.