summaryrefslogtreecommitdiff
path: root/pkg
diff options
context:
space:
mode:
authorDaniel J Walsh <dwalsh@redhat.com>2022-08-23 10:51:21 -0400
committerMatthew Heon <mheon@redhat.com>2022-09-06 14:17:01 -0400
commit455a363bf1eb4040e95105cb22872c7fc529e08f (patch)
tree54055f72f296b9ae95a2fb0d814deecde7ec1b46 /pkg
parentd40175e0aebc64a24f4987d2d1a60f3d7cbe7375 (diff)
downloadpodman-455a363bf1eb4040e95105cb22872c7fc529e08f.tar.gz
podman-455a363bf1eb4040e95105cb22872c7fc529e08f.tar.bz2
podman-455a363bf1eb4040e95105cb22872c7fc529e08f.zip
Allow podman to run in an environment with keys containing spaces
Fixes: https://github.com/containers/podman/issues/15251 Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
Diffstat (limited to 'pkg')
-rw-r--r--pkg/env/env.go20
-rw-r--r--pkg/specgen/generate/container.go6
-rw-r--r--pkg/specgenutil/specgen.go5
3 files changed, 19 insertions, 12 deletions
diff --git a/pkg/env/env.go b/pkg/env/env.go
index 8af9fd77c..fb7949ad8 100644
--- a/pkg/env/env.go
+++ b/pkg/env/env.go
@@ -37,6 +37,22 @@ func Slice(m map[string]string) []string {
return env
}
+// Map transforms the specified slice of environment variables into a
+// map.
+func Map(slice []string) map[string]string {
+ envmap := make(map[string]string, len(slice))
+ for _, val := range slice {
+ data := strings.SplitN(val, "=", 2)
+
+ if len(data) > 1 {
+ envmap[data[0]] = data[1]
+ } else {
+ envmap[data[0]] = ""
+ }
+ }
+ return envmap
+}
+
// Join joins the two environment maps with override overriding base.
func Join(base map[string]string, override map[string]string) map[string]string {
if len(base) == 0 {
@@ -87,10 +103,6 @@ func parseEnv(env map[string]string, line string) error {
}
// trim the front of a variable, but nothing else
name := strings.TrimLeft(data[0], whiteSpaces)
- if strings.ContainsAny(name, whiteSpaces) {
- return fmt.Errorf("name %q has white spaces, poorly formatted name", name)
- }
-
if len(data) > 1 {
env[name] = data[1]
} else {
diff --git a/pkg/specgen/generate/container.go b/pkg/specgen/generate/container.go
index d43c1012f..3bb2ae3d0 100644
--- a/pkg/specgen/generate/container.go
+++ b/pkg/specgen/generate/container.go
@@ -139,10 +139,8 @@ func CompleteSpec(ctx context.Context, r *libpod.Runtime, s *specgen.SpecGenerat
}
// First transform the os env into a map. We need it for the labels later in
// any case.
- osEnv, err := envLib.ParseSlice(os.Environ())
- if err != nil {
- return nil, fmt.Errorf("error parsing host environment variables: %w", err)
- }
+ osEnv := envLib.Map(os.Environ())
+
// Caller Specified defaults
if s.EnvHost {
defaultEnvs = envLib.Join(defaultEnvs, osEnv)
diff --git a/pkg/specgenutil/specgen.go b/pkg/specgenutil/specgen.go
index 9a7d50947..9eb386e81 100644
--- a/pkg/specgenutil/specgen.go
+++ b/pkg/specgenutil/specgen.go
@@ -355,10 +355,7 @@ func FillOutSpecGen(s *specgen.SpecGenerator, c *entities.ContainerCreateOptions
// First transform the os env into a map. We need it for the labels later in
// any case.
- osEnv, err := envLib.ParseSlice(os.Environ())
- if err != nil {
- return fmt.Errorf("error parsing host environment variables: %w", err)
- }
+ osEnv := envLib.Map(os.Environ())
if !s.EnvHost {
s.EnvHost = c.EnvHost