Skip to content

Commit 01cedaa

Browse files
committed
src: improve parsing of boolean options
1 parent 68cc1c9 commit 01cedaa

File tree

4 files changed

+42
-2
lines changed

4 files changed

+42
-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: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,32 @@ test('host port flag should be parsed correctly', { skip: !process.features.insp
232232
strictEqual(result.code, 0);
233233
});
234234

235+
test('--inspect=true should be parsed correctly', { skip: !process.features.inspector }, async () => {
236+
const result = await spawnPromisified(process.execPath, [
237+
'--no-warnings',
238+
'--expose-internals',
239+
'--experimental-config-file',
240+
fixtures.path('rc/inspect-true.json'),
241+
'-p', 'require("internal/options").getOptionValue("--inspect")',
242+
]);
243+
match(result.stderr, /^Debugger listening on (ws:\/\/[^\s]+)/);
244+
strictEqual(result.stdout, 'true\n');
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+
'--expose-internals',
252+
'--experimental-config-file',
253+
fixtures.path('rc/inspect-false.json'),
254+
'-p', 'require("internal/options").getOptionValue("--inspect")',
255+
]);
256+
strictEqual(result.stderr, '');
257+
strictEqual(result.stdout, 'false\n');
258+
strictEqual(result.code, 0);
259+
});
260+
235261
test('no op flag should throw', async () => {
236262
const result = await spawnPromisified(process.execPath, [
237263
'--no-warnings',

0 commit comments

Comments
 (0)