src: improve parsing of boolean options

PR-URL: https://github.com/nodejs/node/pull/58039
Reviewed-By: Marco Ippolito <marcoippolito54@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
This commit is contained in:
Edy Silva authored and RafaelGSS committed 2025-05-02 17:06:59 -03:00
1 parent 304f164f52
commit 130eaa20a4
4 files changed
+40 -2

No files matched your search

+6 -2
View File
@@ -59,8 +59,12 @@ ParseResult ConfigReader::ParseNodeOptions(
FPrintF(stderr, "Invalid value for %s\n", it->first.c_str());
return ParseResult::InvalidContent;
}
node_options_.push_back(it->first + "=" +
(result ? "true" : "false"));
if (result) {
// If the value is true, we need to set the flag
node_options_.push_back(it->first);
}
break;
}
// String array can allow both string and array types
+5
View File
@@ -0,0 +1,5 @@
{
"nodeOptions": {
"inspect": false
}
}
+5
View File
@@ -0,0 +1,5 @@
{
"nodeOptions": {
"inspect": true
}
}
+24
View File
@@ -232,6 +232,30 @@ test('host port flag should be parsed correctly', { skip: !process.features.insp
strictEqual(result.code, 0);
});
test('--inspect=true should be parsed correctly', { skip: !process.features.inspector }, async () => {
const result = await spawnPromisified(process.execPath, [
'--no-warnings',
'--experimental-config-file',
fixtures.path('rc/inspect-true.json'),
'-p', 'require("node:inspector").url()',
]);
match(result.stderr, /^Debugger listening on (ws:\/\/[^\s]+)/);
match(result.stdout, /ws:\/\/[^\s]+/);
strictEqual(result.code, 0);
});
test('--inspect=false should be parsed correctly', { skip: !process.features.inspector }, async () => {
const result = await spawnPromisified(process.execPath, [
'--no-warnings',
'--experimental-config-file',
fixtures.path('rc/inspect-false.json'),
'-p', 'require("node:inspector").url()',
]);
strictEqual(result.stderr, '');
strictEqual(result.stdout, 'undefined\n');
strictEqual(result.code, 0);
});
test('no op flag should throw', async () => {
const result = await spawnPromisified(process.execPath, [
'--no-warnings',