From 4693fc6db14e00db7f1af0b02fad15da35fb3799 Mon Sep 17 00:00:00 2001 From: "Jason T. Greene" Date: Wed, 19 Jan 2022 11:28:09 -0600 Subject: Implement env parsing on Windows Fixes #12056 Also, enables existing parsing logic for all Unix derived OSs Signed-off-by: Jason T. Greene --- pkg/env/env_supported.go | 15 --------------- pkg/env/env_unix.go | 15 +++++++++++++++ pkg/env/env_unsupported.go | 8 -------- pkg/env/env_windows.go | 25 +++++++++++++++++++++++++ 4 files changed, 40 insertions(+), 23 deletions(-) delete mode 100644 pkg/env/env_supported.go create mode 100644 pkg/env/env_unix.go delete mode 100644 pkg/env/env_unsupported.go create mode 100644 pkg/env/env_windows.go diff --git a/pkg/env/env_supported.go b/pkg/env/env_supported.go deleted file mode 100644 index 8be9f9592..000000000 --- a/pkg/env/env_supported.go +++ /dev/null @@ -1,15 +0,0 @@ -// +build linux darwin - -package env - -// ParseSlice parses the specified slice and transforms it into an environment -// map. -func ParseSlice(s []string) (map[string]string, error) { - env := make(map[string]string, len(s)) - for _, e := range s { - if err := parseEnv(env, e); err != nil { - return nil, err - } - } - return env, nil -} diff --git a/pkg/env/env_unix.go b/pkg/env/env_unix.go new file mode 100644 index 000000000..16061a700 --- /dev/null +++ b/pkg/env/env_unix.go @@ -0,0 +1,15 @@ +// +build !windows + +package env + +// ParseSlice parses the specified slice and transforms it into an environment +// map. +func ParseSlice(s []string) (map[string]string, error) { + env := make(map[string]string, len(s)) + for _, e := range s { + if err := parseEnv(env, e); err != nil { + return nil, err + } + } + return env, nil +} diff --git a/pkg/env/env_unsupported.go b/pkg/env/env_unsupported.go deleted file mode 100644 index a71c2956d..000000000 --- a/pkg/env/env_unsupported.go +++ /dev/null @@ -1,8 +0,0 @@ -// +build !linux,!darwin - -package env - -func ParseSlice(s []string) (map[string]string, error) { - m := make(map[string]string) - return m, nil -} diff --git a/pkg/env/env_windows.go b/pkg/env/env_windows.go new file mode 100644 index 000000000..5df08fadc --- /dev/null +++ b/pkg/env/env_windows.go @@ -0,0 +1,25 @@ +package env + +// ParseSlice parses the specified slice and transforms it into an environment +// map. +func ParseSlice(s []string) (map[string]string, error) { + env := make(map[string]string, len(s)) + for _, e := range s { + if len(e) > 0 && e[0] == '=' { + // The legacy Windows CMD command interpreter uses a hack, where to emulate + // DOS semantics, it uses an illegal (by windows definition) env name for + // state storage to avoid conlficting with user defined env names. This is + // used to preserve drive letter paths. E.g., typing c: from another drive + // will remember the last CWD because CMD stores it in an env named "=C:". + // Since these are illegal, they are filtered from standard user access but + // are still available in the underlying win32 API calls. Since they have + // zero value to a container, we filter as well. + continue + } + + if err := parseEnv(env, e); err != nil { + return nil, err + } + } + return env, nil +} -- cgit v1.2.3-54-g00ecf