From bc8eabce252e8363263e9baacdeb1de508029d06 Mon Sep 17 00:00:00 2001 From: Matt Richardson Date: Mon, 5 Sep 2016 08:44:13 +1000 Subject: [PATCH] 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 --- libcontainerd/utils_windows.go | 2 +- libcontainerd/utils_windows_test.go | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) create mode 100644 libcontainerd/utils_windows_test.go diff --git a/libcontainerd/utils_windows.go b/libcontainerd/utils_windows.go index 2126f6457f..70e77bb812 100644 --- a/libcontainerd/utils_windows.go +++ b/libcontainerd/utils_windows.go @@ -10,7 +10,7 @@ import ( func setupEnvironmentVariables(a []string) map[string]string { r := make(map[string]string) for _, s := range a { - arr := strings.Split(s, "=") + arr := strings.SplitN(s, "=", 2) if len(arr) == 2 { r[arr[0]] = arr[1] } diff --git a/libcontainerd/utils_windows_test.go b/libcontainerd/utils_windows_test.go new file mode 100644 index 0000000000..f3679bfb71 --- /dev/null +++ b/libcontainerd/utils_windows_test.go @@ -0,0 +1,13 @@ +package libcontainerd + +import ( + "testing" +) + +func TestEnvironmentParsing(t *testing.T) { + env := []string{"foo=bar", "car=hat", "a=b=c"} + result := setupEnvironmentVariables(env) + if len(result) != 3 || result["foo"] != "bar" || result["car"] != "hat" || result["a"] != "b=c" { + t.Fatalf("Expected map[foo:bar car:hat a:b=c], got %v", result) + } +}