Skip to content

Commit 130eaa2

Browse files
geeksilva97RafaelGSS
authored andcommitted
src: improve parsing of boolean options
PR-URL: #58039 Reviewed-By: Marco Ippolito <marcoippolito54@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
1 parent 304f164 commit 130eaa2

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

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy