浏览代码

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 8 年之前
父节点
当前提交
bc8eabce25
共有 2 个文件被更改,包括 14 次插入1 次删除
  1. 1 1
      libcontainerd/utils_windows.go
  2. 13 0
      libcontainerd/utils_windows_test.go

+ 1 - 1
libcontainerd/utils_windows.go

@@ -10,7 +10,7 @@ import (
 func setupEnvironmentVariables(a []string) map[string]string {
 func setupEnvironmentVariables(a []string) map[string]string {
 	r := make(map[string]string)
 	r := make(map[string]string)
 	for _, s := range a {
 	for _, s := range a {
-		arr := strings.Split(s, "=")
+		arr := strings.SplitN(s, "=", 2)
 		if len(arr) == 2 {
 		if len(arr) == 2 {
 			r[arr[0]] = arr[1]
 			r[arr[0]] = arr[1]
 		}
 		}

+ 13 - 0
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)
+	}
+}