Skip to content

Commit 073daa7

Browse files
committed
src: don't match after -- in Dotenv::GetPathFromArgs
1 parent 3ed9f98 commit 073daa7

File tree

3 files changed

+21
-4
lines changed

3 files changed

+21
-4
lines changed

src/node_dotenv.cc

+6-4
Original file line numberDiff line numberDiff line change
@@ -14,21 +14,23 @@ 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.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+
}
26+
2427
auto equal_char = path->find('=');
2528

2629
if (equal_char != std::string::npos) {
2730
paths.push_back(path->substr(equal_char + 1));
2831
} else {
2932
auto next_path = std::next(path);
30-
31-
if (next_path == args.end()) {
33+
if (next_path == args.end() || *next_path == "--") {
3234
return paths;
3335
}
3436

test/parallel/should-not-write.txt

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
hello

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)