GeezerVison is showing github.com — src: don't match after `--` in `Dotenv::GetPathFromArgs` · nodejs/node@f87aa27
File tree
Expand file treeCollapse file tree
Open diff view settings
Expand file treeCollapse file tree
Open diff view settings
Collapse file
Copy file name to clipboardExpand all lines: src/node_dotenv.cc +4-2Lines changed: 4 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -14,13 +14,15 @@ using v8::String; |
14 | 14 | std::vector<std::string> Dotenv::GetPathFromArgs( |
15 | 15 | const std::vector<std::string>& args) { |
16 | 16 | 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="); |
19 | 18 | }; |
20 | 19 | std::vector<std::string> paths; |
21 | 20 | auto path = std::find_if(args.begin(), args.end(), find_match); |
22 | 21 |
|
23 | 22 | while (path != args.end()) { |
| 23 | + if (*path == "--") { |
| 24 | + return paths; |
| 25 | + } |
24 | 26 | auto equal_char = path->find('='); |
25 | 27 |
|
26 | 28 | if (equal_char != std::string::npos) { |
|
Collapse file
Copy file name to clipboardExpand all lines: test/parallel/test-dotenv-edge-cases.js +14Lines changed: 14 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -98,4 +98,18 @@ describe('.env supports edge cases', () => { |
98 | 98 | assert.strictEqual(child.stderr, ''); |
99 | 99 | assert.strictEqual(child.code, 0); |
100 | 100 | }); |
| 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 | + }); |
101 | 115 | }); |