godotenv icon indicating copy to clipboard operation
godotenv copied to clipboard

Getting double quotes in values in env file

Open HimanshuJha2000 opened this issue 2 years ago • 2 comments

We have a usecase where we let user give their environment variables which we write to a env file using this package, that file will be sent to docker as an env file. While seeing the logs, I observe that I'm getting double quotes over values of env variables due to which the script which I mounted on my docker I've to assume that double quotes have been added to the values of env variables there as well . On debugging through this package, saw this line

for k, v := range envMap {
		if d, err := strconv.Atoi(v); err == nil {
			lines = append(lines, fmt.Sprintf(`%s=%d`, k, d))
		} else {
			lines = append(lines, fmt.Sprintf(`%s="%s"`, k, doubleQuoteEscape(v)))
		}
	}

Where we're adding double quotes over the values in map while appending to the file. Not sure if it's a bug or is being done in this way for some purpose. As of now I move to a different package but want to move back to this package only. Can you please help me with this?

HimanshuJha2000 avatar Jun 06 '23 08:06 HimanshuJha2000

The same problem I have.

I want to set env_A="abc", and env_B="${env_A}_123".

But godotenv gives me env_B="${env_A}_123", the variable syntax is not compatible.

Code like:

envMap, _ := godotenv.Read("some_file")
envMap["env_A"] = "abc"
_ = godotenv.Write(envMap, d.envFile)

envMap["env_B"] = "${env_A}_123"
_ = godotenv.Write(envMap, d.envFile)

and run cat some_file shows:

env_A="abc"
env_B="\${env_A}_123"

fakeyanss avatar Dec 04 '23 08:12 fakeyanss

https://github.com/joho/godotenv/commit/5d289f440502940d9fd8bed27b1c652fa5bca72d#diff-0c241b7f86e85ffca192108ab1d9b8458fbac1d26d43f62fe00d27acac809635R27

fakeyanss avatar Dec 08 '23 02:12 fakeyanss