Repository navigation
util: fix parseEnv incorrectly splitting multiple ‘=‘ in value - #57421
Merged
Merged
Conversation
Collaborator
|
Review requested:
|
Previously, parseEnv would create multiple environment
variables if a single line contained multiple ‘=‘ characters
(e.g. A=B=C would become { A: ‘B=C’, B: ‘C’ }).
This commit ensures that only the first ‘=‘ is used as
the key-value delimiter, and the rest of the line is treated
as the value.
Fixes: nodejs#57411
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #57421 +/- ##
==========================================
- Coverage 90.23% 90.23% -0.01%
==========================================
Files 630 629 -1
Lines 185219 184859 -360
Branches 36248 36215 -33
==========================================
- Hits 167140 166811 -329
+ Misses 11048 11018 -30
+ Partials 7031 7030 -1
🚀 New features to boost your workflow:
|
This comment was marked as off-topic.
This comment was marked as off-topic.
lemire
approved these changes
Mar 12, 2025
aduh95
reviewed
Mar 13, 2025
aduh95
reviewed
Mar 13, 2025
jasnell
reviewed
Mar 13, 2025
Co-authored-by: Antoine du Hamel <duhamelantoine1995@gmail.com>
Co-authored-by: Antoine du Hamel <duhamelantoine1995@gmail.com>
anonrig
reviewed
Mar 13, 2025
Contributor
|
Also, we should keep a test case for the unquoted version |
rayark1
force-pushed
the
fix/57411
branch
2 times, most recently
from
March 14, 2025 18:37
c7267a5 to
255c299
Compare
Contributor
Author
|
I have incorporated all the review comments and added the corresponding test cases. Please let me know if there are any further suggestions or improvements needed. |
Collaborator
Collaborator
Collaborator
|
Landed in e6a0d77 |
RafaelGSS
pushed a commit
that referenced
this pull request
May 1, 2025
Previously, parseEnv would create multiple environment
variables if a single line contained multiple ‘=‘ characters
(e.g. A=B=C would become { A: ‘B=C’, B: ‘C’ }).
This commit ensures that only the first ‘=‘ is used as
the key-value delimiter, and the rest of the line is treated
as the value.
Fixes: #57411
PR-URL: #57421
Reviewed-By: Daniel Lemire <daniel@lemire.me>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
RafaelGSS
pushed a commit
that referenced
this pull request
May 2, 2025
Previously, parseEnv would create multiple environment
variables if a single line contained multiple ‘=‘ characters
(e.g. A=B=C would become { A: ‘B=C’, B: ‘C’ }).
This commit ensures that only the first ‘=‘ is used as
the key-value delimiter, and the rest of the line is treated
as the value.
Fixes: #57411
PR-URL: #57421
Reviewed-By: Daniel Lemire <daniel@lemire.me>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
aduh95
pushed a commit
that referenced
this pull request
May 6, 2025
Previously, parseEnv would create multiple environment
variables if a single line contained multiple ‘=‘ characters
(e.g. A=B=C would become { A: ‘B=C’, B: ‘C’ }).
This commit ensures that only the first ‘=‘ is used as
the key-value delimiter, and the rest of the line is treated
as the value.
Fixes: #57411
PR-URL: #57421
Reviewed-By: Daniel Lemire <daniel@lemire.me>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
RafaelGSS
pushed a commit
that referenced
this pull request
May 14, 2025
Previously, parseEnv would create multiple environment
variables if a single line contained multiple ‘=‘ characters
(e.g. A=B=C would become { A: ‘B=C’, B: ‘C’ }).
This commit ensures that only the first ‘=‘ is used as
the key-value delimiter, and the rest of the line is treated
as the value.
Fixes: #57411
PR-URL: #57421
Reviewed-By: Daniel Lemire <daniel@lemire.me>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
aduh95
pushed a commit
that referenced
this pull request
May 16, 2025
Previously, parseEnv would create multiple environment
variables if a single line contained multiple ‘=‘ characters
(e.g. A=B=C would become { A: ‘B=C’, B: ‘C’ }).
This commit ensures that only the first ‘=‘ is used as
the key-value delimiter, and the rest of the line is treated
as the value.
Fixes: #57411
PR-URL: #57421
Reviewed-By: Daniel Lemire <daniel@lemire.me>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
aduh95
pushed a commit
that referenced
this pull request
May 17, 2025
Previously, parseEnv would create multiple environment
variables if a single line contained multiple ‘=‘ characters
(e.g. A=B=C would become { A: ‘B=C’, B: ‘C’ }).
This commit ensures that only the first ‘=‘ is used as
the key-value delimiter, and the rest of the line is treated
as the value.
Fixes: #57411
PR-URL: #57421
Reviewed-By: Daniel Lemire <daniel@lemire.me>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
aduh95
pushed a commit
that referenced
this pull request
May 19, 2025
Previously, parseEnv would create multiple environment
variables if a single line contained multiple ‘=‘ characters
(e.g. A=B=C would become { A: ‘B=C’, B: ‘C’ }).
This commit ensures that only the first ‘=‘ is used as
the key-value delimiter, and the rest of the line is treated
as the value.
Fixes: #57411
PR-URL: #57421
Reviewed-By: Daniel Lemire <daniel@lemire.me>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
marco-ippolito
pushed a commit
that referenced
this pull request
Aug 18, 2025
Previously, parseEnv would create multiple environment
variables if a single line contained multiple ‘=‘ characters
(e.g. A=B=C would become { A: ‘B=C’, B: ‘C’ }).
This commit ensures that only the first ‘=‘ is used as
the key-value delimiter, and the rest of the line is treated
as the value.
Fixes: #57411
PR-URL: #57421
Reviewed-By: Daniel Lemire <daniel@lemire.me>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
marco-ippolito
pushed a commit
that referenced
this pull request
Aug 20, 2025
Previously, parseEnv would create multiple environment
variables if a single line contained multiple ‘=‘ characters
(e.g. A=B=C would become { A: ‘B=C’, B: ‘C’ }).
This commit ensures that only the first ‘=‘ is used as
the key-value delimiter, and the rest of the line is treated
as the value.
Fixes: #57411
PR-URL: #57421
Reviewed-By: Daniel Lemire <daniel@lemire.me>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
marco-ippolito
pushed a commit
that referenced
this pull request
Aug 20, 2025
Previously, parseEnv would create multiple environment
variables if a single line contained multiple ‘=‘ characters
(e.g. A=B=C would become { A: ‘B=C’, B: ‘C’ }).
This commit ensures that only the first ‘=‘ is used as
the key-value delimiter, and the rest of the line is treated
as the value.
Fixes: #57411
PR-URL: #57421
Reviewed-By: Daniel Lemire <daniel@lemire.me>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
marco-ippolito
pushed a commit
that referenced
this pull request
Aug 23, 2025
Previously, parseEnv would create multiple environment
variables if a single line contained multiple ‘=‘ characters
(e.g. A=B=C would become { A: ‘B=C’, B: ‘C’ }).
This commit ensures that only the first ‘=‘ is used as
the key-value delimiter, and the rest of the line is treated
as the value.
Fixes: #57411
PR-URL: #57421
Reviewed-By: Daniel Lemire <daniel@lemire.me>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
marco-ippolito
pushed a commit
that referenced
this pull request
Aug 25, 2025
Previously, parseEnv would create multiple environment
variables if a single line contained multiple ‘=‘ characters
(e.g. A=B=C would become { A: ‘B=C’, B: ‘C’ }).
This commit ensures that only the first ‘=‘ is used as
the key-value delimiter, and the rest of the line is treated
as the value.
Fixes: #57411
PR-URL: #57421
Reviewed-By: Daniel Lemire <daniel@lemire.me>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
marco-ippolito
pushed a commit
that referenced
this pull request
Aug 25, 2025
Previously, parseEnv would create multiple environment
variables if a single line contained multiple ‘=‘ characters
(e.g. A=B=C would become { A: ‘B=C’, B: ‘C’ }).
This commit ensures that only the first ‘=‘ is used as
the key-value delimiter, and the rest of the line is treated
as the value.
Fixes: #57411
PR-URL: #57421
Reviewed-By: Daniel Lemire <daniel@lemire.me>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
marco-ippolito
pushed a commit
that referenced
this pull request
Aug 25, 2025
Previously, parseEnv would create multiple environment
variables if a single line contained multiple ‘=‘ characters
(e.g. A=B=C would become { A: ‘B=C’, B: ‘C’ }).
This commit ensures that only the first ‘=‘ is used as
the key-value delimiter, and the rest of the line is treated
as the value.
Fixes: #57411
PR-URL: #57421
Reviewed-By: Daniel Lemire <daniel@lemire.me>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
marco-ippolito
pushed a commit
that referenced
this pull request
Aug 27, 2025
Previously, parseEnv would create multiple environment
variables if a single line contained multiple ‘=‘ characters
(e.g. A=B=C would become { A: ‘B=C’, B: ‘C’ }).
This commit ensures that only the first ‘=‘ is used as
the key-value delimiter, and the rest of the line is treated
as the value.
Fixes: #57411
PR-URL: #57421
Reviewed-By: Daniel Lemire <daniel@lemire.me>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
DaveHanns
added a commit
to apify/apify-cli
that referenced
this pull request
Nov 23, 2026
util.parseEnv misparses .env on Node.js versions that engines (>=22)
allows:
- 22.1.0 to 22.15.0 and every 23.x: a line without '=' or an indented
comment swallows the next key ('JUNK\nB=2' gives 'JUNK\nB'), and '='
in a last-line value adds a key ('X=a=b' adds 'a'). 22.1.0 brought the
hand-written parser (nodejs/node#52406). The fixes (nodejs/node#57421,
nodejs/node#57798) shipped in 22.16.0 and 24.0.0, never in 23.x
(doc/changelogs/CHANGELOG_V22.md, CHANGELOG_V24.md).
- 22.15.0 also turns base64 padding into keys ('B64=YWJj==' adds ''
and 'YWJj').
- 25.0.0 and later return a null-prototype object (nodejs/node#60038).
Raising engines is a product decision, and skipping .env on those
versions would drop the feature with a warning. The env commands also
need the numbers of malformed lines, which parseEnv can't give. So
parse with a small line-based parser that follows the parser of 22.16.0
and later (src/node_dotenv.cc, the same in 22.16.0, 24.11.0 and main).
A differential fuzz (500,000 to 2,000,000 random inputs on 22.16.0,
24.22.1 and 26.4.0) matches parseEnv except where parseEnv itself is
wrong: a line without a name (kept as '' or parsed again from its
value), a value of only spaces (takes the next line), 'export NAME='
(keeps 'export NAME'), and an indented comment after a comment or an
empty value (becomes a '#...' variable). The new tests pass on 22.15.0,
23.8.0, 22.16.0, 24.22.1 and 26.4.0; with parseEnv, three fail on
22.15.0 and 23.8.0 and one on 26.4.0.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Previously, parseEnv would create multiple environment variables if a single line contained multiple ‘=‘ characters (e.g. A=B=C would become { A: ‘B=C’, B: ‘C’ }).
This commit ensures that only the first ‘=‘ is used as the key-value delimiter, and the rest of the line is treated as the value.
Fixes: #57411