Skip to content

util: fix parseEnv handling of invalid lines - #56778

Closed
AugustinMauroy wants to merge 0 commit into
nodejs:mainfrom
AugustinMauroy:util-fix-parseEnv-handling-of-invalid-lines
Closed

util: fix parseEnv handling of invalid lines#56778
AugustinMauroy wants to merge 0 commit into
nodejs:mainfrom
AugustinMauroy:util-fix-parseEnv-handling-of-invalid-lines

Conversation

@AugustinMauroy

Copy link
Copy Markdown
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-botnodejs-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
AugustinMauroyforce-pushed the util-fix-parseEnv-handling-of-invalid-lines branch from de3dd86 to 8dd566fCompareJanuary 26, 2025 23:53

@anonriganonrig left a comment

Copy link
Copy Markdown
Member

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.

Comment threadtest/parallel/test-dotenv-invalid-syntax.js Outdated
Comment threadsrc/node_dotenv.cc Outdated
Comment threadsrc/node_dotenv.cc Outdated
Comment threadsrc/node_dotenv.cc Outdated
Comment threadsrc/node_dotenv.cc
Comment threadsrc/node_dotenv.cc Outdated
@codecov

codecovBot commented Jan 27, 2025

Copy link
Copy Markdown

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 linesPatch %Lines
src/node_dotenv.cc83.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 linesCoverage Δ
src/node_dotenv.cc85.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
Copy Markdown
MemberAuthor

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
anonrig previously requested changes Jan 27, 2025
Comment threadsrc/node_dotenv.cc Outdated
Comment threadsrc/node_dotenv.cc
Comment threadsrc/node_dotenv.cc Outdated
Comment threadsrc/node_dotenv.cc Outdated
Comment threadsrc/node_dotenv.cc Outdated
Comment threadsrc/node_dotenv.cc Outdated
Comment threadsrc/node_dotenv.cc Outdated
Comment threadsrc/node_dotenv.cc Outdated
Comment threadsrc/node_dotenv.cc
@anonrig

Copy link
Copy Markdown
Member

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
Copy Markdown
MemberAuthor

Bump @anonrig 👋

@anonrig

Copy link
Copy Markdown
Member

Bump @anonrig 👋

@AugustinMauroy the tests are failing

@AugustinMauroy

Copy link
Copy Markdown
MemberAuthor

@AugustinMauroy the tests are failing

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

@targos

Copy link
Copy Markdown
Member

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

Comment threadtest/parallel/test-dotenv-edge-cases.js Outdated
Comment threadtest/parallel/test-dotenv-edge-cases.js Outdated
Comment threadtest/parallel/test-dotenv-edge-cases.js Outdated
@AugustinMauroy
AugustinMauroyforce-pushed the util-fix-parseEnv-handling-of-invalid-lines branch from 51d9aad to 2a6ba9dCompareFebruary 6, 2025 09:35
Comment threadsrc/node_dotenv.cc Outdated
Comment threadsrc/node_dotenv.cc Outdated
Comment threadsrc/node_dotenv.cc Outdated
Comment threadsrc/node_dotenv.cc Outdated
Comment threadsrc/node_dotenv.cc Outdated
Comment threadsrc/node_dotenv.cc Outdated
Comment threadtest/parallel/test-dotenv-edge-cases.js Outdated
Comment threadtest/parallel/test-dotenv-edge-cases.js Outdated
@mertcanaltin

mertcanaltin commented Feb 14, 2025

Copy link
Copy Markdown
Member

@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
Copy Markdown
MemberAuthor

Thanks mert 🫶🏻

@RafaelGSSRafaelGSS added the request-ci Add this label to start a Jenkins CI on a PR. label Feb 28, 2025
@github-actionsgithub-actionsBot removed the request-ci Add this label to start a Jenkins CI on a PR. label Feb 28, 2025
@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

Comment on lines 209 to 211

Copy link
Copy Markdown
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
Copy Markdown
MemberAuthor

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

Comment threadtest/parallel/test-dotenv-edge-cases.js Outdated
Comment threadtest/parallel/test-dotenv-edge-cases.js Outdated
Comment threadtest/parallel/test-dotenv-edge-cases.js Outdated
@AugustinMauroy
AugustinMauroyforce-pushed the util-fix-parseEnv-handling-of-invalid-lines branch 2 times, most recently from 093636d to 2f90eb1CompareMarch 19, 2025 21:21
@AugustinMauroy

Copy link
Copy Markdown
MemberAuthor

@anonrig any new ?

@anonrig
anonrig dismissed their stale reviewMarch 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.

Comment threadtest/parallel/test-dotenv-edge-cases.js Outdated
Comment threadtest/parallel/test-dotenv-edge-cases.js Outdated
Comment threadtest/parallel/test-dotenv-edge-cases.js Outdated
Comment threadtest/parallel/test-dotenv-edge-cases.js Outdated
Comment threadtest/parallel/test-dotenv-edge-cases.js Outdated
Comment threadtest/parallel/test-dotenv-edge-cases.js Outdated
Comment threadtest/parallel/test-dotenv-edge-cases.js Outdated
Comment threadtest/parallel/test-dotenv-edge-cases.js Outdated
Comment threadtest/parallel/test-dotenv-edge-cases.js Outdated
@aduh95aduh95 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-actionsgithub-actionsBot removed the request-ci Add this label to start a Jenkins CI on a PR. label Apr 1, 2025
@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

@aduh95

Copy link
Copy Markdown
Contributor

This needs a rebase to fix the conflict

@AugustinMauroy

Copy link
Copy Markdown
MemberAuthor

I'll do that !

Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

author readyPRs 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++.needs-ciPRs 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

8 participants

@AugustinMauroy@anonrig@targos@mertcanaltin@nodejs-github-bot@aduh95@RafaelGSS@marco-ippolito