Skip to content

Commit

Permalink
Windows: Case insensitive env vars
Browse files Browse the repository at this point in the history
Signed-off-by: John Howard <jhoward@microsoft.com>
  • Loading branch information
John Howard committed Nov 23, 2016
1 parent 06e92cc commit b2049a8
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
7 changes: 7 additions & 0 deletions runconfig/opts/opts.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
"net"
"os"
"runtime"
"strings"

fopts "github.com/docker/docker/opts"
Expand Down Expand Up @@ -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
}
Expand Down
5 changes: 5 additions & 0 deletions runconfig/opts/opts_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package opts
import (
"fmt"
"os"
"runtime"
"strings"
"testing"
)
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit b2049a8

Please sign in to comment.