Skip to content

Commit 7bf98eb

Browse files
committed
src: add validation for CLI arguments that don't take a value
1 parent 7178e91 commit 7bf98eb

1 file changed

Lines changed: 8 additions & 0 deletions

File tree

src/node_options-inl.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,10 @@ inline std::string RequiresArgumentErr(const std::string& arg) {
268268
return arg + " requires an argument";
269269
}
270270

271+
inline std::string UnexpectedArgumentErr(const std::string& arg) {
272+
return arg + " does not take an argument";
273+
}
274+
271275
inline std::string NegationImpliesBooleanError(const std::string& arg) {
272276
return arg + " is an invalid negation because it is not a boolean option";
273277
}
@@ -475,6 +479,10 @@ void OptionsParser<Options>::Parse(
475479
value = value.substr(1); // Treat \- as escaping an -.
476480
}
477481
}
482+
} else if (info.type == kBoolean && equals_index != std::string::npos) {
483+
// Boolean options don't accept arguments
484+
errors->push_back(UnexpectedArgumentErr(name));
485+
break;
478486
}
479487

480488
switch (info.type) {

0 commit comments

Comments
 (0)