godotenv
godotenv copied to clipboard
BUG: Variable not correct
In .env
file:
zzz=kAjMfB<Qdq$7KJ!HbFO3o9Vi?acrxnI(eDl^GhEmSL4[2Xz*vs58Z+NY10R6Uw%y
Variable after being read back:
kAjMfB<Qdq$7KJ!HbFO3o9Vi?acrxnI(eDl^GhEmSL4[2Xz*vs58Z+NY10R6Uw%y
This is not correct:
kAjMfB<Qdq!HbFO3o9Vi?acrxnI(eDl^GhEmSL4[2Xz*vs58Z+NY10R6Uw%y
kAjMfB<Qdq$7KJ!HbFO3o9Vi?acrxnI(eDl^GhEmSL4[2Xz*vs58Z+NY10R6Uw%y
I can observe similar issue, but my variable contains (hash)
In .env file
a=samplevalue#willcut
After godotenv.Load() and os.Getenv
a=samplevalue
Also seeing the same as @grzany
@grzany I believe #
gets interpreted as comment.
@pjebs yes, I suspect so
This looks like intended behaviour - $7KJ
is being interpreted as a variable and expanded (to nothing). $
should be escaped or removed.
How do you escape?
How do you escape?
\$
should do it. You may need to escape the escape character itself like this \\$
.
It doesn't say anywhere in docs that you need to escape. In fact, we should not have to escape at all because passwords etc may legitimately have $ characters
Disclaimer - I'm not a maintainer of this library, but I would guess it doesn't mention it in the docs as it isn't a behaviour specific to this library. Variable expansion using $
happens both on the command line (tested in bash
), and in other popular env packages such as dotenv
through their dotenv-expand
package.
same issue here, string with #
is not properly loaded.
I think the issue is related to the Regex operation performed in function expandVariables,
ENV(s): ENV1="MfNPjwKVDs273Q3J4w%k3utcuJpseWx$5EHSK9FY5wQzPP%vWme%X" ENV2="kAjMfB<Qdq$7KJ!HbFO3o9Vi?acrxnI(eDl^GhEmSL4[2Xz*vs58Z+NY10R6Uw%y"
Result: ENV1 = MfNPjwKVDs273Q3J4w%k3utcuJpseWxwQzPP%vWme%X ENV2 = kAjMfB<Qdq!HbFO3o9Vi?acrxnI(eDl^GhEmSL4[2Xz*vs58Z+NY10R6Uw%y
The Result over Commented expandVariables: ENV1 = MfNPjwKVDs273Q3J4w%k3utcuJpseWx$5EHSK9FY5wQzPP%vWme%X ENV2 = kAjMfB<Qdq$7KJ!HbFO3o9Vi?acrxnI(eDl^GhEmSL4[2Xz*vs58Z+NY10R6Uw%y
Another solution: stripping off #
and everything after should probably be replaced with stripping off <space>#
and everything after, so that a #
in a string doesn't get treated as a comment: https://github.com/joho/godotenv/blob/ddf83eb33bbb136f62617a409142b74b91dbcff3/godotenv.go#L230-L232