Skip to content

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

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

@dario-piotrowiczdario-piotrowiczforce-pushed the dario/56686/spaces-tabs-in-env-file branch from 1eb6236 to eabaf64CompareFebruary 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-piotrowiczdario-piotrowiczforce-pushed the dario/56686/spaces-tabs-in-env-file branch from eabaf64 to 47d1a76CompareFebruary 10, 2025 00:36
@dario-piotrowicz
Copy link
MemberAuthor

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

I've applied all your suggested changes 🙂

@anonriganonrig 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-actionsgithub-actionsbot 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

@codecov
Copy link

codecovbot 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 linesPatch %Lines
src/node_dotenv.cc60.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 linesCoverage Δ
src/node_dotenv.cc91.25% <60.00%> (-1.53%)⬇️

... and 27 files with indirect coverage changes

@anonrig
Copy link
Member

@dario-piotrowicz the tests are failing

remove pos_start == pos_end check
@dario-piotrowicz
Copy link
MemberAuthor

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-piotrowiczdario-piotrowiczforce-pushed the dario/56686/spaces-tabs-in-env-file branch from 6d32733 to c261fb4CompareFebruary 10, 2025 10:37
@anonriganonrig added the request-ci Add this label to start a Jenkins CI on a PR. label Feb 10, 2025
@github-actionsgithub-actionsbot 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

@anonriganonrig requested a review from jasnellFebruary 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
MemberAuthor

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?

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

Landed in 43ffcf1

@dario-piotrowiczdario-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 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.

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

4 participants

@dario-piotrowicz@anonrig@nodejs-github-bot@jasnell