Repository navigation
util.parseEnv creates keys from invalid, newline-separated lines #56775
Description
Activity
How does dotenv handle this? I think this is expected behavior.
- addeddotenvIssues and PRs related to .env file parsing.Issues and PRs related to .env file parsing.
on Jan 26, 2025 IMO node should output:
{ foo: true, bar: true, baz: 'whatever', }
and dotenv do that
const dotenv = require('dotenv'); const input = ` foo bar baz=whatever `; const output = dotenv.parse(input); console.log(output); // => { baz: 'whatever' }
Tested on v24.0.0-pre
I think dotenv's behavior is more correct. But dotenv also supports multiline arguments. I think we shouldn't accept newline characters when parsing key's
supports multiline arguments
I never heard about that. Could you give me an example.
you mean that ?
supports multiline arguments
I never heard about that. Could you give me an example.
you mean that ?
Line 72 of https://github.com/nodejs/node/blob/main/test/parallel/test-dotenv.js
+1 for Dotenv behavior. We should use same fixtures
Can I fix this issue ? i know the answers is yes But I mean is it an easy task.
And where is the affected code ?+1 for Dotenv behavior. We should use same fixtures
Can I fix this issue ? i know the answers is yes But I mean is it an easy task.
And where is the affected code ?Yes, node_dotenv.cc
Reacted by Augustin Mauroy- addedconfirmed-bugIssues and PRs for confirmed bugs.Issues and PRs for confirmed bugs.
on Jan 26, 2025 But dotenv also supports multiline arguments
I think multiline arguments are more common than multiline keys
IMO node should output:
{
foo: true,
bar: true,
baz: 'whatever',
}I'll go with whatever the consensus is, but IMHO
fooandbarin that example shouldn't set totrue, since there is no=. sign. It seems like stricter behavior would be safer.Since one doesn't exist, I thought i would get a spec started for
.env: https://github.com/env-lang/env/blob/main/env.mdI'm open to any level of contributions if anyone is interested.
- added a commit that references this issue
on Apr 21, 2025 - added 2 commits that reference this issue
on May 1, 2025 - added 2 commits that reference this issue
on May 6, 2025 - added a commit that references this issue
on May 14, 2025
Version
v23.6.1
Platform
Subsystem
No response
What steps will reproduce the bug?
Do:
Then create a string with some invalid lines:
And parse it:
How often does it reproduce? Is there a required condition?
Tested on node versions v21x-v23.6.1
What is the expected behavior? Why is that the expected behavior?
Expected behavior, IMHO, would be throw an invalid syntax error.
What do you see instead?
Invalid output.
Additional information
No response