Merge pull request #28667 from Microsoft/jjh/env-case-sensitive

Windows: Case insensitive env vars
This commit is contained in:
John Howard 2016-11-23 14:40:16 -08:00 committed by GitHub
commit f93c04d1ed
2 changed files with 12 additions and 0 deletions

View File

@ -4,6 +4,7 @@ import (
"fmt" "fmt"
"net" "net"
"os" "os"
"runtime"
"strings" "strings"
fopts "github.com/docker/docker/opts" fopts "github.com/docker/docker/opts"
@ -45,6 +46,12 @@ func ValidateEnv(val string) (string, error) {
func doesEnvExist(name string) bool { func doesEnvExist(name string) bool {
for _, entry := range os.Environ() { for _, entry := range os.Environ() {
parts := strings.SplitN(entry, "=", 2) 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 { if parts[0] == name {
return true return true
} }

View File

@ -3,6 +3,7 @@ package opts
import ( import (
"fmt" "fmt"
"os" "os"
"runtime"
"strings" "strings"
"testing" "testing"
) )
@ -50,6 +51,10 @@ func TestValidateEnv(t *testing.T) {
" some space before": " some space before", " some space before": " some space before",
"some space after ": "some space after ", "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 { for value, expected := range valids {
actual, err := ValidateEnv(value) actual, err := ValidateEnv(value)
if err != nil { if err != nil {