Skip to content

--env-file parses commented out parts, when they contain quotation marks #51508

Closed
@pano9000

Description

@pano9000

Version

v20.9.0

Platform

Microsoft Windows NT 10.0.22621.0 x64

Subsystem

No response

What steps will reproduce the bug?

when using a .env file with entries like the one below, where there is a commented out part, nodeJS will parse the whole line as value, instead of just the expected "VALUE1" part.

KEY="VALUE1" # or "VALUE2" or "VALUE3"

How often does it reproduce? Is there a required condition?

Only happens, if the commented out part contains quotation marks as well.
Comments without quotation marks are correctly ignored, e.g.

KEY="VALUE1" # or 'VALUE2' or 'VALUE3' will correctly only parse the VALUE1 part as value

What is the expected behavior? Why is that the expected behavior?

process.env.KEY should have the value VALUE1 only, the rest of the line is a comment that should not be parsed

What do you see instead?

Currently it parsed the whole line instead, removing the first and last quotation mark:
PROD" # or "TEST" or "DEV

So it looks like the behaviour currently is to find the first and last quotation mark and treat everything in between as the value.

The same line, when parsed by dotenv does not give the same wrong result.

Additional information

No response

Metadata

Metadata

Labels

confirmed-bugIssues with confirmed bugs.dotenvIssues and PRs related to .env file parsing

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions