From efb86bae8be169c8e9be991a290ea073c180ca45 Mon Sep 17 00:00:00 2001 From: RedYetiDev <38299977+RedYetiDev@users.noreply.github.com> Date: Wed, 7 Aug 2024 17:21:21 -0400 Subject: [PATCH] src: don't match after` --` in `Dotenv::GetPathFromArgs` --- src/node_dotenv.cc | 8 +++++--- test/parallel/test-dotenv-edge-cases.js | 14 ++++++++++++++ 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/src/node_dotenv.cc b/src/node_dotenv.cc index 9e0205b4e6249f..eccff31f81949b 100644 --- a/src/node_dotenv.cc +++ b/src/node_dotenv.cc @@ -14,12 +14,15 @@ using v8::String; std::vector Dotenv::GetPathFromArgs( const std::vector& args) { const auto find_match = [](const std::string& arg) { - const std::string_view flag = "--env-file"; - return strncmp(arg.c_str(), flag.data(), flag.size()) == 0; + return arg == "--" || arg == "--env-file" || arg.starts_with("--env-file="); }; std::vector paths; auto path = std::find_if(args.begin(), args.end(), find_match); + if (*path == "--") { + return paths; + } + while (path != args.end()) { auto equal_char = path->find('='); @@ -27,7 +30,6 @@ std::vector Dotenv::GetPathFromArgs( paths.push_back(path->substr(equal_char + 1)); } else { auto next_path = std::next(path); - if (next_path == args.end()) { return paths; } diff --git a/test/parallel/test-dotenv-edge-cases.js b/test/parallel/test-dotenv-edge-cases.js index f8cd262c8a8092..5528d0b47fecb1 100644 --- a/test/parallel/test-dotenv-edge-cases.js +++ b/test/parallel/test-dotenv-edge-cases.js @@ -98,4 +98,18 @@ describe('.env supports edge cases', () => { assert.strictEqual(child.stderr, ''); assert.strictEqual(child.code, 0); }); + + it('should handle when --env-file is passed along with --', async () => { + const child = await common.spawnPromisified( + process.execPath, + [ + '--eval', `require('assert').strictEqual(process.env.BASIC, undefined);`, + '--', '--env-file', validEnvFilePath, + ], + { cwd: fixtures.path('dotenv') }, + ); + assert.strictEqual(child.stdout, ''); + assert.strictEqual(child.stderr, ''); + assert.strictEqual(child.code, 0); + }); });