瀏覽代碼

Windows: Case insensitive env vars

Signed-off-by: John Howard <jhoward@microsoft.com>
(cherry picked from commit b2049a84dee35308ca8c4837ccb9359f57808f45)
Signed-off-by: Victor Vieux <victorvieux@gmail.com>
John Howard 8 年之前
父節點
當前提交
35a87689e4
共有 2 個文件被更改,包括 12 次插入0 次删除
  1. 7 0
      runconfig/opts/opts.go
  2. 5 0
      runconfig/opts/opts_test.go

+ 7 - 0
runconfig/opts/opts.go

@@ -4,6 +4,7 @@ import (
 	"fmt"
 	"net"
 	"os"
+	"runtime"
 	"strings"
 
 	fopts "github.com/docker/docker/opts"
@@ -45,6 +46,12 @@ func ValidateEnv(val string) (string, error) {
 func doesEnvExist(name string) bool {
 	for _, entry := range os.Environ() {
 		parts := strings.SplitN(entry, "=", 2)
+		if runtime.GOOS == "windows" {
+			// Environment variable are case-insensitive on Windows. PaTh, path and PATH are equivalent.
+			if strings.EqualFold(parts[0], name) {
+				return true
+			}
+		}
 		if parts[0] == name {
 			return true
 		}

+ 5 - 0
runconfig/opts/opts_test.go

@@ -3,6 +3,7 @@ package opts
 import (
 	"fmt"
 	"os"
+	"runtime"
 	"strings"
 	"testing"
 )
@@ -50,6 +51,10 @@ func TestValidateEnv(t *testing.T) {
 		"  some space before": "  some space before",
 		"some space after  ":  "some space after  ",
 	}
+	// Environment variables are case in-sensitive on Windows
+	if runtime.GOOS == "windows" {
+		valids["PaTh"] = fmt.Sprintf("PaTh=%v", os.Getenv("PATH"))
+	}
 	for value, expected := range valids {
 		actual, err := ValidateEnv(value)
 		if err != nil {