-
-
Notifications
You must be signed in to change notification settings - Fork 861
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
leading/trailing spaces inside quotes are skipped #197
Comments
The ".env syntax" is loosely based on INI file format. It is intentional that dotenv "trims" values. That "trimming behavior" has been around for almost 4 years (see v0.0.1) and I think this is the first time it has come up in an issue. Maybe we should document in the README? |
Thanks - and yeah, it did seem reminiscent of ini, and I did a brief look around to see if there was a standard for the syntax, but came up short in a quick google search; figured I'd ask. Adding a note to the README sounds like a good idea - I expected the trimming without any quotes, but seeing it occur with the quotes took me a bit by surprise, since at that point the spaces would be there intentionally. Still, it's telling that I'm the first person to bring it up, and if someone wants similar ini-like syntax without that behavior, there's always TOML. I only came across it because I was looking for things to account for with the serializer I was cooking up (more or less for a build script that generates/prompts people for values via inquirer). |
I also ran into this issue as I need a value that has a leading space (don't ask, it's stupid I know but I can't change it in the receiving end). IMO it would make more sense to trim only unquoted strings and leave quoted strings as is, because with quotes it's more obvious that the whitespace is part of the value. e.g.
would output: {
foo: "some value",
bar: " some value "
} Should be pretty simple change, just swap the trim before the replace in this line: Line 31 in 40e9efc
|
Hi!
I noticed this today while tinkering with a CLI script that serializes .env files that dotenv appears to be stripping leading and trailing whitespace from the values even when surrounded by quotes - is that intentional/a part of the .env syntax? I'm guessing not, since it would cause issues with, for example, passwords that contain leading/trailing spaces.
Test case (with v4.0.0):
.env
Output
The text was updated successfully, but these errors were encountered: