Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BUG: Variable not correct #127

Open
pjebs opened this issue Dec 4, 2020 · 12 comments
Open

BUG: Variable not correct #127

pjebs opened this issue Dec 4, 2020 · 12 comments

Comments

@pjebs
Copy link

pjebs commented Dec 4, 2020

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
@grzany
Copy link

grzany commented Jan 14, 2021

I can observe similar issue, but my variable contains (hash)
In .env file
a=samplevalue#willcut
After godotenv.Load() and os.Getenv
a=samplevalue

@technicaljones
Copy link

Also seeing the same as @grzany

@pjebs
Copy link
Author

pjebs commented Jan 14, 2021

@grzany I believe # gets interpreted as comment.

@grzany
Copy link

grzany commented Jan 14, 2021

@pjebs yes, I suspect so

@LauSam09
Copy link

This looks like intended behaviour - $7KJ is being interpreted as a variable and expanded (to nothing). $ should be escaped or removed.

@pjebs
Copy link
Author

pjebs commented Jan 23, 2021

How do you escape?

@LauSam09
Copy link

LauSam09 commented Jan 23, 2021

How do you escape?

\$ should do it. You may need to escape the escape character itself like this \\$.

@pjebs
Copy link
Author

pjebs commented Jan 23, 2021

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

@LauSam09
Copy link

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.

Screenshot from 2021-01-23 21-26-21

@vx3r
Copy link

vx3r commented Feb 18, 2021

same issue here, string with # is not properly loaded.

@vaibhavmunjal
Copy link

vaibhavmunjal commented Feb 28, 2021

I think the issue is related to the Regex operation performed in function expandVariables,

image

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

@elimisteve
Copy link

elimisteve commented Jun 9, 2021

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:

godotenv/godotenv.go

Lines 230 to 232 in ddf83eb

// ditch the comments (but keep quoted hashes)
if strings.Contains(line, "#") {
segmentsBetweenHashes := strings.Split(line, "#")

hoshsadiq added a commit to hoshsadiq/godotenv that referenced this issue Dec 13, 2021
When a hash is part of the environment value, without a preceding
whitespace, it should not be interpreted as a comment.

Fixes joho/godotenv#127
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants