| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 73b5c16 commit 9097de0
2 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -14,13 +14,22 @@ 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 | + auto arg_chars = arg.c_str(); | ||
| 18 | + auto arg_len = arg.size(); | ||
| 19 | + if (arg_chars[0] != '-' || arg_chars[1] != '-') return false; | ||
| 20 | + if (arg_len == 2) return true; // arg == "--" | ||
| 21 | + const std::string_view flag = "env-file"; | ||
| 22 | + const auto len = flag.size(); | ||
| 23 | + if (strncmp(arg_chars + 2, flag.data(), len) != 0) return false; | ||
| 24 | + return arg_len == 2 + len || arg_chars[2 + len] == '='; | ||
| 19 | 25 | }; | |
| 20 | 26 | std::vector<std::string> paths; | |
| 21 | 27 | auto path = std::find_if(args.begin(), args.end(), find_match); | |
| 22 | 28 | ||
| 23 | 29 | while (path != args.end()) { | |
| 30 | + if (path->size() == 2 && strncmp(path->c_str(), "--", 2) == 0) { | ||
| 31 | + return paths; | ||
| 32 | + } | ||
| 24 | 33 | auto equal_char = path->find('='); | |
| 25 | 34 | ||
| 26 | 35 | if (equal_char != std::string::npos) { | |
| 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', '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 | }); | |
| Back | FazBrowse Home | New Git URL |
0 commit comments