Skip to content

Commit 880c446

Browse files
avivkellerxduugu
andauthored
src: don't match after -- in Dotenv::GetPathFromArgs
Co-Authored-By: Cedric Staniewski <[email protected]> PR-URL: #54237 Reviewed-By: Yagiz Nizipli <[email protected]> Reviewed-By: Antoine du Hamel <[email protected]>
1 parent 123693c commit 880c446

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

src/node_dotenv.cc

+4-2
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,15 @@ using v8::String;
1414
std::vector<std::string> Dotenv::GetPathFromArgs(
1515
const std::vector<std::string>& args) {
1616
const auto find_match = [](const std::string& arg) {
17-
const std::string_view flag = "--env-file";
18-
return strncmp(arg.c_str(), flag.data(), flag.size()) == 0;
17+
return arg == "--" || arg == "--env-file" || arg.starts_with("--env-file=");
1918
};
2019
std::vector<std::string> paths;
2120
auto path = std::find_if(args.begin(), args.end(), find_match);
2221

2322
while (path != args.end()) {
23+
if (*path == "--") {
24+
return paths;
25+
}
2426
auto equal_char = path->find('=');
2527

2628
if (equal_char != std::string::npos) {

test/parallel/test-dotenv-edge-cases.js

+14
Original file line numberDiff line numberDiff line change
@@ -98,4 +98,18 @@ describe('.env supports edge cases', () => {
9898
assert.strictEqual(child.stderr, '');
9999
assert.strictEqual(child.code, 0);
100100
});
101+
102+
it('should handle when --env-file is passed along with --', async () => {
103+
const child = await common.spawnPromisified(
104+
process.execPath,
105+
[
106+
'--eval', `require('assert').strictEqual(process.env.BASIC, undefined);`,
107+
'--', '--env-file', validEnvFilePath,
108+
],
109+
{ cwd: fixtures.path('dotenv') },
110+
);
111+
assert.strictEqual(child.stdout, '');
112+
assert.strictEqual(child.stderr, '');
113+
assert.strictEqual(child.code, 0);
114+
});
101115
});

0 commit comments

Comments
 (0)