Skip to content
Open
Show file tree
Hide file tree
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
8 changes: 8 additions & 0 deletions src/node_options-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,10 @@ inline std::string RequiresArgumentErr(const std::string& arg) {
return arg + " requires an argument";
}

inline std::string UnexpectedArgumentErr(const std::string& arg) {
return arg + " does not take an argument";
}

inline std::string NegationImpliesBooleanError(const std::string& arg) {
return arg + " is an invalid negation because it is not a boolean option";
}
Expand Down Expand Up @@ -475,6 +479,10 @@ void OptionsParser<Options>::Parse(
value = value.substr(1); // Treat \- as escaping an -.
}
}
} else if (info.type == kBoolean && equals_index != std::string::npos) {
// Boolean options don't accept arguments
errors->push_back(UnexpectedArgumentErr(name));
break;
}

switch (info.type) {
Expand Down
14 changes: 14 additions & 0 deletions test/parallel/test-cli-bad-options.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ requiresArgument('--eval');
missingOption('--allow-fs-read=*', '--permission');
missingOption('--allow-fs-write=*', '--permission');

forbidsArgument('--check');

function missingOption(option, requiredOption) {
const r = spawnSync(process.execPath, [option], { encoding: 'utf8' });
assert.strictEqual(r.status, 1);
Expand All @@ -36,3 +38,15 @@ function requiresArgument(option) {
`${process.execPath}: ${option} requires an argument`
);
}

function forbidsArgument(option) {
const r = spawnSync(process.execPath, [`${option}=invalid`], { encoding: 'utf8' });

assert.strictEqual(r.status, 9);

const msg = r.stderr.split(/\r?\n/)[0];
assert.strictEqual(
msg,
`${process.execPath}: ${option} does not take an argument`
);
}
Loading