Skip to content

src: improve node::Dotenv trimming #56983

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

Conversation

dario-piotrowicz
Copy link
Member

the trimming functionality that the dotenv parsing uses currently only takes into consideration plain spaces (' '), other type of space characters such as tabs and newlines are not trimmed, this can cause subtle bugs, so the changes here make sure that such characters get trimmed as well

Fixes #56686

@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 Feb 9, 2025
@dario-piotrowicz dario-piotrowicz force-pushed the dario/56686/spaces-tabs-in-env-file branch 6 times, most recently from 3dba125 to ff0ffe4 Compare February 9, 2025 22:52
@dario-piotrowicz dario-piotrowicz force-pushed the dario/56686/spaces-tabs-in-env-file branch 2 times, most recently from b5dd12f to 00d9449 Compare February 10, 2025 00:14
@anonrig
Copy link
Member

anonrig commented Feb 10, 2025

Looking good. After these changes, we can land this pull-request. @dario-piotrowicz

@dario-piotrowicz dario-piotrowicz force-pushed the dario/56686/spaces-tabs-in-env-file branch from 1eb6236 to eabaf64 Compare February 10, 2025 00:36
the trimming functionality that the dotenv parsing uses currently
only takes into consideration plain spaces (' '), other type of
space characters such as tabs and newlines are not trimmed, this
can cause subtle bugs, so the changes here make sure that such
characters get trimmed as well

Co-authored-by: Yagiz Nizipli <[email protected]>
@dario-piotrowicz dario-piotrowicz force-pushed the dario/56686/spaces-tabs-in-env-file branch from eabaf64 to 47d1a76 Compare February 10, 2025 00:36
@dario-piotrowicz
Copy link
Member Author

@anonrig thank you very much for your review and help here 🙏 (and sorry for the silly mistakes 😓)

I've applied all your suggested changes 🙂

@anonrig anonrig 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 Feb 10, 2025
@github-actions github-actions bot removed the request-ci Add this label to start a Jenkins CI on a PR. label Feb 10, 2025
@nodejs-github-bot
Copy link
Collaborator

Copy link

codecov bot commented Feb 10, 2025

Codecov Report

Attention: Patch coverage is 60.00000% with 4 lines in your changes missing coverage. Please review.

Project coverage is 89.13%. Comparing base (d1f8ccb) to head (c261fb4).
Report is 24 commits behind head on main.

Files with missing lines Patch % Lines
src/node_dotenv.cc 60.00% 2 Missing and 2 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #56983      +/-   ##
==========================================
- Coverage   89.13%   89.13%   -0.01%     
==========================================
  Files         665      665              
  Lines      193167   193177      +10     
  Branches    37190    37193       +3     
==========================================
+ Hits       172185   172192       +7     
- Misses      13731    13743      +12     
+ Partials     7251     7242       -9     
Files with missing lines Coverage Δ
src/node_dotenv.cc 91.25% <60.00%> (-1.53%) ⬇️

... and 27 files with indirect coverage changes

@anonrig
Copy link
Member

anonrig commented Feb 10, 2025

@dario-piotrowicz the tests are failing

remove pos_start == pos_end check
@dario-piotrowicz
Copy link
Member Author

dario-piotrowicz commented Feb 10, 2025

@dario-piotrowicz the tests are failing

Sorry about that, I've addressed it 🙂 (e3ee074)

The issue was this new check:

if (pos_start == pos_end) {
  return "";
}

since if pos_start is the same as pos_end that shouldn't result in an empty string but in a single character at that position (input.at(post_start))

I removed the check completely (instead of returning input.at(pos_start)) since when pos_start and post_end are the same return input.substr(pos_start, pos_end - pos_start + 1); should work just fine (as it would resolve to return input.substr(pos_start, 1); meaning that it'd take a single character starting from pos_start)

do you agree?


PS: that's not the only issue 🤔

add check for when no value is present
@dario-piotrowicz dario-piotrowicz force-pushed the dario/56686/spaces-tabs-in-env-file branch from 6d32733 to c261fb4 Compare February 10, 2025 10:37
@anonrig anonrig added the request-ci Add this label to start a Jenkins CI on a PR. label Feb 10, 2025
@github-actions github-actions bot removed the request-ci Add this label to start a Jenkins CI on a PR. label Feb 10, 2025
@nodejs-github-bot
Copy link
Collaborator

@anonrig anonrig requested a review from jasnell February 10, 2025 13:38
if (input.front() == ' ') {
input.remove_prefix(input.find_first_not_of(' '));

auto pos_start = input.find_first_not_of(" \t\n");
Copy link
Member

Choose a reason for hiding this comment

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

should this also include \r and \f?

Copy link
Member Author

Choose a reason for hiding this comment

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

sounds good to me 🙂, but I'm not sure how to test that, would you be ok with addition without dedicated tests for it?

@anonrig anonrig added the commit-queue Add this label to land a pull request using GitHub Actions. label Feb 11, 2025
@nodejs-github-bot nodejs-github-bot removed the commit-queue Add this label to land a pull request using GitHub Actions. label Feb 11, 2025
@nodejs-github-bot nodejs-github-bot merged commit 43ffcf1 into nodejs:main Feb 11, 2025
57 checks passed
@nodejs-github-bot
Copy link
Collaborator

Landed in 43ffcf1

@dario-piotrowicz dario-piotrowicz deleted the dario/56686/spaces-tabs-in-env-file branch February 12, 2025 00:11
targos pushed a commit that referenced this pull request Feb 17, 2025
the trimming functionality that the dotenv parsing uses currently
only takes into consideration plain spaces (' '), other type of
space characters such as tabs and newlines are not trimmed, this
can cause subtle bugs, so the changes here make sure that such
characters get trimmed as well

Co-authored-by: Yagiz Nizipli <[email protected]>
PR-URL: #56983
Reviewed-By: Yagiz Nizipli <[email protected]>
Reviewed-By: James M Snell <[email protected]>
acidiney pushed a commit to acidiney/node that referenced this pull request Feb 23, 2025
the trimming functionality that the dotenv parsing uses currently
only takes into consideration plain spaces (' '), other type of
space characters such as tabs and newlines are not trimmed, this
can cause subtle bugs, so the changes here make sure that such
characters get trimmed as well

Co-authored-by: Yagiz Nizipli <[email protected]>
PR-URL: nodejs#56983
Reviewed-By: Yagiz Nizipli <[email protected]>
Reviewed-By: James M Snell <[email protected]>
aduh95 pushed a commit that referenced this pull request Apr 2, 2025
the trimming functionality that the dotenv parsing uses currently
only takes into consideration plain spaces (' '), other type of
space characters such as tabs and newlines are not trimmed, this
can cause subtle bugs, so the changes here make sure that such
characters get trimmed as well

Co-authored-by: Yagiz Nizipli <[email protected]>
PR-URL: #56983
Reviewed-By: Yagiz Nizipli <[email protected]>
Reviewed-By: James M Snell <[email protected]>
aduh95 pushed a commit that referenced this pull request Apr 3, 2025
the trimming functionality that the dotenv parsing uses currently
only takes into consideration plain spaces (' '), other type of
space characters such as tabs and newlines are not trimmed, this
can cause subtle bugs, so the changes here make sure that such
characters get trimmed as well

Co-authored-by: Yagiz Nizipli <[email protected]>
PR-URL: #56983
Reviewed-By: Yagiz Nizipli <[email protected]>
Reviewed-By: James M Snell <[email protected]>
RafaelGSS pushed a commit that referenced this pull request Apr 16, 2025
the trimming functionality that the dotenv parsing uses currently
only takes into consideration plain spaces (' '), other type of
space characters such as tabs and newlines are not trimmed, this
can cause subtle bugs, so the changes here make sure that such
characters get trimmed as well

Co-authored-by: Yagiz Nizipli <[email protected]>
PR-URL: #56983
Reviewed-By: Yagiz Nizipli <[email protected]>
Reviewed-By: James M Snell <[email protected]>
RafaelGSS pushed a commit that referenced this pull request Apr 17, 2025
the trimming functionality that the dotenv parsing uses currently
only takes into consideration plain spaces (' '), other type of
space characters such as tabs and newlines are not trimmed, this
can cause subtle bugs, so the changes here make sure that such
characters get trimmed as well

Co-authored-by: Yagiz Nizipli <[email protected]>
PR-URL: #56983
Reviewed-By: Yagiz Nizipli <[email protected]>
Reviewed-By: James M Snell <[email protected]>
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++. needs-ci PRs that need a full CI run.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

when loading env file (--env-file), env variable will not be loaded if preceding 'blank' line contains space(s) or tab(s)
4 participants