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

Doesn't support multiline vars #64

Closed
esttorhe opened this issue Dec 18, 2018 · 16 comments
Closed

Doesn't support multiline vars #64

esttorhe opened this issue Dec 18, 2018 · 16 comments

Comments

@esttorhe
Copy link

If I set something like this:

KEY='this is
a multiline
variable'

godotenv returns:

Can't separate key from value

Even though that's a valid variable assignment.

I'm currently at work; will attempt a fix later this week.

@joho
Copy link
Owner

joho commented Jan 29, 2019

While most of the discussion on this is happening in #65 I'd rather talk about it here in case the ultimate solution is a different PR.

Given I use the ruby dotenv implementation as the informal spec a solution should follow the form of bkeepers/dotenv@b3bd635 and expand newlines within double quotes only.

@joho joho mentioned this issue Jan 29, 2019
6 tasks
@esttorhe
Copy link
Author

Thanks for pointing out the spec @joho

I'll try to amend my PR today addressing this

@joho
Copy link
Owner

joho commented Jan 29, 2019

BTW I'm aware the internals need a fair overhaul and if that's a job you don't necessarily want to take on don't feel like you have to,

@esttorhe
Copy link
Author

No need to worry man; I'm glad you took the time to put together this library 😊

I wouldn't mind tweaking the internals; although I would take a jab at it on a different PR

@esttorhe
Copy link
Author

@joho this faf711c should handle the multiline «similar» to the spec on dotenv.

Later we can/should change the logic to rely on regular expressions as well.

For now it will look for " as the delimiters for multiline values

@dschmidt
Copy link

dschmidt commented Aug 21, 2019

Given I use the ruby dotenv implementation as the informal spec a solution should follow the form of bkeepers/dotenv@b3bd635 and expand newlines within double quotes only.

I would like to point out that it's possible to use \n in double quoted strings to have new lines in env vars. This wasn't clear to me when checking the readme and I realised it only when reading the code. It's not as nice as true multiline strings but at least it unblocks me right now 😇

@inoda
Copy link

inoda commented Oct 22, 2019

Any updates on this? I am still having issues with the following env var:

EXAMPLE="-----BEGIN RSA PRIVATE KEY-----\n
abc\n
123\n
-----END RSA PRIVATE KEY-----"

I am still getting Failed to setup application - cannot continue: Can't separate key from value

@jeffwalsh
Copy link

inoda if you base64encode it for now and store it as that in the .env file, its a happy workaround, then just base64decode it when you need to use the env variable

@dschmidt
Copy link

dschmidt commented Dec 6, 2019

@inoda You can probably just remove the actual line breaks (keeping the \n) and it should work.

@joho
Copy link
Owner

joho commented Nov 8, 2020

I haven't yet had a close look at #118 but that may address it

paddatrapper added a commit to flanksource/karina that referenced this issue Jan 21, 2021
@joho
Copy link
Owner

joho commented Apr 10, 2021

bkeepers/dotenv#423 some changes in the upstream lib to maintain compatibility with

@thinh090
Copy link

Screen Shot 2021-07-31 at 10 57 50 PM

this works for me

@joho
Copy link
Owner

joho commented Jan 27, 2023

This is now fixed via #156 (which was an expansion of #118)

Thanks @x1unix for the bulk of the work, and @austinsasko and @coolaj86 for some key suggestions.

Sorry it took so long... go's no longer my daily driver, startup life, parent life, and frankly i've always been bad at "chores"

Release plan is to let it sit on main for a while, see if anyone raises regressions. I might do a prerelease version number, might not. Then will release as a minor version bump.

@joho joho closed this as completed Jan 27, 2023
@joho
Copy link
Owner

joho commented Jan 27, 2023

Pre-release at https://github.com/joho/godotenv/releases/tag/v1.5.0-beta.0

@joho
Copy link
Owner

joho commented Feb 4, 2023

I've received no complaints or bug reports about the pre-release, so I shall act as though absence of evidence is evidence of absence.

Pushing actual release today.

@asainnp
Copy link

asainnp commented Jan 13, 2024

It seems that multiline var reading works very well. But writing back to file NOT working.
If you just read some file with multiline var, unmarshal to map and write file back, it will be written \n instead of real newline (byte10).
Problem is that godotenv.write is calling 'Marshal', then 'Marshal' calls 'doubleQuoteEscape', and doubleQuoteEscape function doing exactly that for some reason, if c=='\n', toReplace=\n.

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

Successfully merging a pull request may close this issue.

7 participants