Browse code

A fix for = in env values in linked containers

Closes: #12763

Signed-off-by: Doug Davis <dug@us.ibm.com>

Doug Davis authored on 2015/04/25 20:42:43
Showing 2 changed files
... ...
@@ -310,3 +310,24 @@ func (s *DockerSuite) TestLinksUpdateOnRestart(c *check.C) {
310 310
 		c.Fatalf("For 'onetwo' alias expected IP: %s, got: %s", realIP, ip)
311 311
 	}
312 312
 }
313
+
314
+func (s *DockerSuite) TestLinksEnvs(c *check.C) {
315
+	runCmd := exec.Command(dockerBinary, "run", "-d", "-e", "e1=", "-e", "e2=v2", "-e", "e3=v3=v3", "--name=first", "busybox", "top")
316
+	out, _, _, err := runCommandWithStdoutStderr(runCmd)
317
+	if err != nil {
318
+		c.Fatalf("Run of first failed: %s\n%s", out, err)
319
+	}
320
+
321
+	runCmd = exec.Command(dockerBinary, "run", "--name=second", "--link=first:first", "busybox", "env")
322
+
323
+	out, stde, rc, err := runCommandWithStdoutStderr(runCmd)
324
+	if err != nil || rc != 0 {
325
+		c.Fatalf("run of 2nd failed: rc: %d, out: %s\n err: %s", rc, out, stde)
326
+	}
327
+
328
+	if !strings.Contains(out, "FIRST_ENV_e1=\n") ||
329
+		!strings.Contains(out, "FIRST_ENV_e2=v2") ||
330
+		!strings.Contains(out, "FIRST_ENV_e3=v3=v3") {
331
+		c.Fatalf("Incorrect output: %s", out)
332
+	}
333
+}
... ...
@@ -107,8 +107,8 @@ func (l *Link) ToEnv() []string {
107 107
 
108 108
 	if l.ChildEnvironment != nil {
109 109
 		for _, v := range l.ChildEnvironment {
110
-			parts := strings.Split(v, "=")
111
-			if len(parts) != 2 {
110
+			parts := strings.SplitN(v, "=", 2)
111
+			if len(parts) < 2 {
112 112
 				continue
113 113
 			}
114 114
 			// Ignore a few variables that are added during docker build (and not really relevant to linked containers)