Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
avivkeller committed Aug 15, 2024
1 parent 8511b3c commit 35c4dae
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/node_dotenv.cc
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ std::vector<std::string> Dotenv::GetPathFromArgs(
paths.push_back(arg.substr(11)); // Directly extract the path
} else if (arg == "--env-file" && i + 1 < args.size()) {
paths.push_back(args[++i]); // Advance to the next argument
} else if (arg[1] != '-') {
} else if (arg.length() == 2 && arg[1] != '-') {
++i; // Skip short argument values (like `-e <...>`)
}
}
Expand Down
9 changes: 8 additions & 1 deletion test/cctest/test_dotenv.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ using node::Dotenv;
ASSERT_EQ(check_result.size(), expected.size()); \
for (size_t i = 0; i < check_result.size(); ++i) { \
EXPECT_EQ(check_result[i], expected[i]); \
}
} \
}

TEST(Dotenv, GetPathFromArgs) {
CHECK_DOTENV(({"node", "--env-file=.env"}),
Expand All @@ -31,4 +32,10 @@ TEST(Dotenv, GetPathFromArgs) {

CHECK_DOTENV(({"node", "-e", "...", "--env-file=after.env"}),
(std::vector<std::string>{"after.env"}));

CHECK_DOTENV(({"node", "-too_long", "--env-file=.env"}),
(std::vector<std::string>{".env"}));

CHECK_DOTENV(({"node", "-", "--env-file=.env"}),
(std::vector<std::string>{".env"}));
}

0 comments on commit 35c4dae

Please sign in to comment.