mirror of
https://github.com/nodejs/node.git
synced 2026-11-09 15:11:11 -05:00
src: don't match after -- in Dotenv::GetPathFromArgs
Co-Authored-By: Cedric Staniewski <cedric@gmx.ca> PR-URL: https://github.com/nodejs/node/pull/54237 Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com> Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
This commit is contained in:
1 parent
6aa1d9e855
commit
f87aa27274
2 files changed
+18
-2
No files matched your search
+4
-2
@@ -14,13 +14,15 @@ using v8::String;
|
||||
std::vector<std::string> Dotenv::GetPathFromArgs(
|
||||
const std::vector<std::string>& 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<std::string> paths;
|
||||
auto path = std::find_if(args.begin(), args.end(), find_match);
|
||||
|
||||
while (path != args.end()) {
|
||||
if (*path == "--") {
|
||||
return paths;
|
||||
}
|
||||
auto equal_char = path->find('=');
|
||||
|
||||
if (equal_char != std::string::npos) {
|
||||
|
||||
@@ -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);
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user