Skip to content

Commit

Permalink
Fix code for splitting KEY=VALUE env vars
Browse files Browse the repository at this point in the history
Make the code work with env values with "=" in them as well as entries of the
form "KEY" (no "=")
  • Loading branch information
md5 committed Feb 28, 2015
1 parent 9978084 commit 4de4160
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
7 changes: 5 additions & 2 deletions docker-gen.go
Expand Up @@ -100,8 +100,11 @@ type Context []*RuntimeContainer
func (c *Context) Env() map[string]string {

env := make(map[string]string)
for _, i := range os.Environ() {
parts := strings.Split(i, "=")
for _, entry := range os.Environ() {
parts := strings.SplitN(entry, "=", 2)
if len(parts) != 2 {
parts = append(parts, "")
}
env[parts[0]] = parts[1]
}
return env
Expand Down
5 changes: 4 additions & 1 deletion docker_client.go
Expand Up @@ -148,7 +148,10 @@ func getContainers(client *docker.Client) ([]*RuntimeContainer, error) {
}

for _, entry := range container.Config.Env {
parts := strings.Split(entry, "=")
parts := strings.SplitN(entry, "=", 2)
if len(parts) != 2 {
parts = append(parts, "")
}
runtimeContainer.Env[parts[0]] = parts[1]
}

Expand Down

0 comments on commit 4de4160

Please sign in to comment.