Repository navigation
util: fix parseEnv handling of invalid lines - #57798
nodejs-github-bot merged 2 commits into
Conversation
|
Review requested:
|
| // The value pair should be `value` | ||
| if (hash_character != std::string_view::npos) { | ||
| value = content.substr(0, hash_character); | ||
| value = value.substr(0, hash_character); |
There was a problem hiding this comment.
Why did you make this change? Please add a test that covers this.
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #57798 +/- ##
==========================================
- Coverage 90.23% 90.23% -0.01%
==========================================
Files 630 630
Lines 185288 185294 +6
Branches 36344 36341 -3
==========================================
- Hits 167203 167202 -1
- Misses 11006 11017 +11
+ Partials 7079 7075 -4
π New features to boost your workflow:
|
|
I had added some test case for |
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
| // Returns an empty string_view if the input is empty. | ||
| // Example: | ||
| // trim_spaces(" hello ") -> "hello" | ||
| // trim_spaces("") -> "" |
There was a problem hiding this comment.
Not new to this PR but it occurs to me that this function overlooks the often-overlooked vertical tab (0x0B).
There was a problem hiding this comment.
I maybe can help on that, but I don't know what your are talking about
|
Landed in 64d9b7c |
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 PR fixes an issue with
util.parseEnv()where invalid lines in the input were being incorrectly concatenated into key names instead of being skipped. The fix ensures that lines without an equals sign are properly skipped during parsingFixes: #56775
I lost my old pr due to a git failure π
#56778