Skip to content
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

util: fix parseEnv handling of invalid lines #56778

Conversation

AugustinMauroy
Copy link
Member

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 parsing

Fixes: #56775

@nodejs-github-bot nodejs-github-bot added c++ Issues and PRs that require attention from people who are familiar with C++. needs-ci PRs that need a full CI run. labels Jan 26, 2025
@AugustinMauroy AugustinMauroy force-pushed the util-fix-parseEnv-handling-of-invalid-lines branch from de3dd86 to 8dd566f Compare January 26, 2025 23:53
Copy link
Member

@anonrig anonrig left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work!

Even though this test pass, I strongly recommend adding as much as comment possible while simplifying your code. Our parser is already complex (due to not using a regex) and it would help a lot if we know why such decision is taken in the parser.

Copy link

codecov bot commented Jan 27, 2025

Codecov Report

Attention: Patch coverage is 83.33333% with 5 lines in your changes missing coverage. Please review.

Project coverage is 90.23%. Comparing base (1540fc6) to head (6719205).
Report is 3 commits behind head on main.

Files with missing lines Patch % Lines
src/node_dotenv.cc 83.33% 3 Missing and 2 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #56778      +/-   ##
==========================================
- Coverage   90.23%   90.23%   -0.01%     
==========================================
  Files         630      630              
  Lines      185288   185295       +7     
  Branches    36344    36339       -5     
==========================================
- Hits       167203   167199       -4     
- Misses      11006    11009       +3     
- Partials     7079     7087       +8     
Files with missing lines Coverage Δ
src/node_dotenv.cc 85.20% <83.33%> (+1.60%) ⬆️

... and 24 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@AugustinMauroy
Copy link
Member Author

Yup yagizz, I had tried to apply yours suggestions. I'm reaching my limit in C++. So I hope that this time if it's good.

@anonrig
Copy link
Member

anonrig commented Jan 27, 2025

Yup yagizz, I had tried to apply yours suggestions. I'm reaching my limit in C++. So I hope that this time if it's good.

I see lots of changes unrelated to your PR. Can you revert everything that is unrelated to your change?

@AugustinMauroy
Copy link
Member Author

Bump @anonrig 👋

@anonrig
Copy link
Member

anonrig commented Feb 6, 2025

Bump @anonrig 👋

@AugustinMauroy the tests are failing

@AugustinMauroy
Copy link
Member Author

@AugustinMauroy the tests are failing

How to run test that fail ?? I din't get what should I do

@targos
Copy link
Member

targos commented Feb 6, 2025

@aduh95 Maybe you could help here? The failure is specific to directories with special chars.

@AugustinMauroy AugustinMauroy force-pushed the util-fix-parseEnv-handling-of-invalid-lines branch from 51d9aad to 2a6ba9d Compare February 6, 2025 09:35
@mertcanaltin
Copy link
Member

mertcanaltin commented Feb 14, 2025

@AugustinMauroy the tests are failing

How to run test that fail ?? I din't get what should I do

This should work make test-only (for c and js)

if it is a specific js test ./node test-name.js

for more:
https://github.com/nodejs/node/blob/main/BUILDING.md#running-tests

@AugustinMauroy
Copy link
Member Author

Thanks mert 🫶🏻

@RafaelGSS RafaelGSS added the request-ci Add this label to start a Jenkins CI on a PR. label Feb 28, 2025
@github-actions github-actions bot removed the request-ci Add this label to start a Jenkins CI on a PR. label Feb 28, 2025
@nodejs-github-bot
Copy link
Collaborator

@nodejs-github-bot
Copy link
Collaborator

Comment on lines 209 to 211
const input = fs.readFileSync(${JSON.stringify(invalidEnvFilePath)}, 'utf8');
assert.deepStrictEqual(util.parseEnv(input), {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Wouldn't it make more sense to put the content here rather in a fixture file?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The rest of tests use an fixture so I just do it as same

@AugustinMauroy AugustinMauroy requested a review from anonrig March 19, 2025 20:34
@AugustinMauroy AugustinMauroy force-pushed the util-fix-parseEnv-handling-of-invalid-lines branch 2 times, most recently from 093636d to 2f90eb1 Compare March 19, 2025 21:21
@AugustinMauroy
Copy link
Member Author

@anonrig any new ?

@anonrig anonrig dismissed their stale review March 22, 2025 18:26

I will take a look at it soon, but I'm unblocking in case there is someone who can review this faster.

@aduh95 aduh95 added author ready PRs that have at least one approval, no pending requests for changes, and a CI started. request-ci Add this label to start a Jenkins CI on a PR. labels Mar 22, 2025
@github-actions github-actions bot removed the request-ci Add this label to start a Jenkins CI on a PR. label Apr 1, 2025
@nodejs-github-bot
Copy link
Collaborator

@aduh95
Copy link
Contributor

aduh95 commented Apr 7, 2025

This needs a rebase to fix the conflict

@aduh95 aduh95 added the lts-watch-v20.x PRs that may need to be released in v20.x label Apr 7, 2025
@AugustinMauroy
Copy link
Member Author

I'll do that !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
author ready PRs that have at least one approval, no pending requests for changes, and a CI started. c++ Issues and PRs that require attention from people who are familiar with C++. lts-watch-v20.x PRs that may need to be released in v20.x needs-ci PRs that need a full CI run.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

util.parseEnv creates keys from invalid, newline-separated lines
7 participants