Skip to content

Commit cab2423

Browse files
geeksilva97aduh95
authored andcommitted
src: improve parsing of boolean options
PR-URL: #58039 Reviewed-By: Marco Ippolito <[email protected]> Reviewed-By: Colin Ihrig <[email protected]>
1 parent 2896760 commit cab2423

File tree

4 files changed

+40
-2
lines changed

4 files changed

+40
-2
lines changed

src/node_config_file.cc

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,12 @@ ParseResult ConfigReader::ParseNodeOptions(
5959
FPrintF(stderr, "Invalid value for %s\n", it->first.c_str());
6060
return ParseResult::InvalidContent;
6161
}
62-
node_options_.push_back(it->first + "=" +
63-
(result ? "true" : "false"));
62+
63+
if (result) {
64+
// If the value is true, we need to set the flag
65+
node_options_.push_back(it->first);
66+
}
67+
6468
break;
6569
}
6670
// String array can allow both string and array types

test/fixtures/rc/inspect-false.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"nodeOptions": {
3+
"inspect": false
4+
}
5+
}

test/fixtures/rc/inspect-true.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"nodeOptions": {
3+
"inspect": true
4+
}
5+
}

test/parallel/test-config-file.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,30 @@ test('host port flag should be parsed correctly', { skip: !process.features.insp
233233
strictEqual(result.code, 0);
234234
});
235235

236+
test('--inspect=true should be parsed correctly', { skip: !process.features.inspector }, async () => {
237+
const result = await spawnPromisified(process.execPath, [
238+
'--no-warnings',
239+
'--experimental-config-file',
240+
fixtures.path('rc/inspect-true.json'),
241+
'-p', 'require("node:inspector").url()',
242+
]);
243+
match(result.stderr, /^Debugger listening on (ws:\/\/[^\s]+)/);
244+
match(result.stdout, /ws:\/\/[^\s]+/);
245+
strictEqual(result.code, 0);
246+
});
247+
248+
test('--inspect=false should be parsed correctly', { skip: !process.features.inspector }, async () => {
249+
const result = await spawnPromisified(process.execPath, [
250+
'--no-warnings',
251+
'--experimental-config-file',
252+
fixtures.path('rc/inspect-false.json'),
253+
'-p', 'require("node:inspector").url()',
254+
]);
255+
strictEqual(result.stderr, '');
256+
strictEqual(result.stdout, 'undefined\n');
257+
strictEqual(result.code, 0);
258+
});
259+
236260
test('no op flag should throw', async () => {
237261
const result = await spawnPromisified(process.execPath, [
238262
'--no-warnings',

0 commit comments

Comments
 (0)