From 34e0bfdfe9eb16ee39ae00c92b7118a65c4b77f7 Mon Sep 17 00:00:00 2001 From: Jose Diaz-Gonzalez Date: Thu, 7 May 2020 14:43:56 -0400 Subject: [PATCH] fix: ensure empty keys are not added to the environment There appears to be cases where empty keys related to the basher path are injected into the env, causing identifier issues. This completely removes that possibiity. --- basher.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/basher.go b/basher.go index 083c86b..76bd3c9 100644 --- a/basher.go +++ b/basher.go @@ -213,6 +213,11 @@ func (c *Context) buildEnvfile() (string, error) { file.Write([]byte("export SELF=" + os.Args[0] + "\n")) file.Write([]byte("export SELF_EXECUTABLE='" + c.SelfPath + "'\n")) for _, kvp := range c.vars { + pair := strings.SplitN(kvp, "=", 2) + if len(pair) != 2 || strings.TrimSpace(pair[0]) == "" { + continue + } + file.Write([]byte("export " + strings.Replace( strings.Replace(kvp, "'", "\\'", -1), "=", "=$'", 1) + "'\n")) }