Skip to content

Commit ce5397e

Browse files
committed
Add validation for CLI arguments that don't take a value
1 parent 7178e91 commit ce5397e

1 file changed

Lines changed: 10 additions & 0 deletions

File tree

src/node_options-inl.h

Lines changed: 10 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,12 @@ void OptionsParser<Options>::Parse(
475479
value = value.substr(1); // Treat \- as escaping an -.
476480
}
477481
}
482+
} else if (info.type == kBoolean) {
483+
if (equals_index != std::string::npos) {
484+
// Boolean options don't accept arguments
485+
errors->push_back(UnexpectedArgumentErr(name));
486+
break;
487+
}
478488
}
479489

480490
switch (info.type) {

0 commit comments

Comments
 (0)