Signed-off-by: John Howard <jhoward@microsoft.com>
(cherry picked from commit b2049a84dee35308ca8c4837ccb9359f57808f45)
Signed-off-by: Victor Vieux <victorvieux@gmail.com>
| ... | ... |
@@ -4,6 +4,7 @@ import ( |
| 4 | 4 |
"fmt" |
| 5 | 5 |
"net" |
| 6 | 6 |
"os" |
| 7 |
+ "runtime" |
|
| 7 | 8 |
"strings" |
| 8 | 9 |
|
| 9 | 10 |
fopts "github.com/docker/docker/opts" |
| ... | ... |
@@ -45,6 +46,12 @@ func ValidateEnv(val string) (string, error) {
|
| 45 | 45 |
func doesEnvExist(name string) bool {
|
| 46 | 46 |
for _, entry := range os.Environ() {
|
| 47 | 47 |
parts := strings.SplitN(entry, "=", 2) |
| 48 |
+ if runtime.GOOS == "windows" {
|
|
| 49 |
+ // Environment variable are case-insensitive on Windows. PaTh, path and PATH are equivalent. |
|
| 50 |
+ if strings.EqualFold(parts[0], name) {
|
|
| 51 |
+ return true |
|
| 52 |
+ } |
|
| 53 |
+ } |
|
| 48 | 54 |
if parts[0] == name {
|
| 49 | 55 |
return true |
| 50 | 56 |
} |
| ... | ... |
@@ -3,6 +3,7 @@ package opts |
| 3 | 3 |
import ( |
| 4 | 4 |
"fmt" |
| 5 | 5 |
"os" |
| 6 |
+ "runtime" |
|
| 6 | 7 |
"strings" |
| 7 | 8 |
"testing" |
| 8 | 9 |
) |
| ... | ... |
@@ -50,6 +51,10 @@ func TestValidateEnv(t *testing.T) {
|
| 50 | 50 |
" some space before": " some space before", |
| 51 | 51 |
"some space after ": "some space after ", |
| 52 | 52 |
} |
| 53 |
+ // Environment variables are case in-sensitive on Windows |
|
| 54 |
+ if runtime.GOOS == "windows" {
|
|
| 55 |
+ valids["PaTh"] = fmt.Sprintf("PaTh=%v", os.Getenv("PATH"))
|
|
| 56 |
+ } |
|
| 53 | 57 |
for value, expected := range valids {
|
| 54 | 58 |
actual, err := ValidateEnv(value) |
| 55 | 59 |
if err != nil {
|