镜像站点 · 本页由第三方 GitHub 只读镜像提供,非 GitHub 官方站点,不接受任何登录或凭据输入。前往 github.com
Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 11 additions & 5 deletions src/node_options-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,10 @@ void OptionsParser<Options>::Parse(
if (equals_index != std::string::npos)
original_name += '=';

auto missing_argument = [&]() {
errors->push_back(RequiresArgumentErr(original_name));
};

// Normalize by replacing `_` with `-` in options.
for (std::string::size_type i = 2; i < name.size(); ++i) {
if (name[i] == '_')
Expand Down Expand Up @@ -381,18 +385,20 @@ void OptionsParser<Options>::Parse(
if (equals_index != std::string::npos) {
value = arg.substr(equals_index + 1);
if (value.empty()) {
missing_argument:
errors->push_back(RequiresArgumentErr(original_name));
missing_argument();
break;
}
} else {
if (args.empty())
goto missing_argument;
if (args.empty()) {
missing_argument();
break;
}

value = args.pop_first();

if (!value.empty() && value[0] == '-') {
goto missing_argument;
missing_argument();
break;
} else {
if (!value.empty() && value[0] == '\\' && value[1] == '-')
value = value.substr(1); // Treat \- as escaping an -.
Expand Down