Browse code

Allow windows environment variables to contain `=`

Fix issue where environment variables with embedded equals signs were
being dropped and not passed to the container.

Fixes #26178.

Signed-off-by: Matt Richardson <matt.richardson@octopus.com>

Matt Richardson authored on 2016/09/05 07:44:13
Showing 2 changed files
... ...
@@ -10,7 +10,7 @@ import (
10 10
 func setupEnvironmentVariables(a []string) map[string]string {
11 11
 	r := make(map[string]string)
12 12
 	for _, s := range a {
13
-		arr := strings.Split(s, "=")
13
+		arr := strings.SplitN(s, "=", 2)
14 14
 		if len(arr) == 2 {
15 15
 			r[arr[0]] = arr[1]
16 16
 		}
17 17
new file mode 100644
... ...
@@ -0,0 +1,13 @@
0
+package libcontainerd
1
+
2
+import (
3
+	"testing"
4
+)
5
+
6
+func TestEnvironmentParsing(t *testing.T) {
7
+	env := []string{"foo=bar", "car=hat", "a=b=c"}
8
+	result := setupEnvironmentVariables(env)
9
+	if len(result) != 3 || result["foo"] != "bar" || result["car"] != "hat" || result["a"] != "b=c" {
10
+		t.Fatalf("Expected map[foo:bar car:hat a:b=c], got %v", result)
11
+	}
12
+}