godotenv
godotenv copied to clipboard
Doesn't support multiline vars
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.
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 https://github.com/bkeepers/dotenv/commit/b3bd6357f80981941d78e51fe86aeaf66cdcc60f and expand newlines within double quotes only.
Thanks for pointing out the spec @joho
I'll try to amend my PR today addressing this
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,
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
@joho this faf711c01668ace5365389b124816a2e06778197 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
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 :innocent:
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
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
@inoda You can probably just remove the actual line breaks (keeping the \n
) and it should work.
I haven't yet had a close look at #118 but that may address it
https://github.com/bkeepers/dotenv/pull/423 some changes in the upstream lib to maintain compatibility with
![Screen Shot 2021-07-31 at 10 57 50 PM](https://user-images.githubusercontent.com/7253938/127745528-97e1f36e-5523-4eae-9218-cc0dfeaa8968.png)
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.
Pre-release at https://github.com/joho/godotenv/releases/tag/v1.5.0-beta.0
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.
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
.