From 01cedaa599bf92884ae855e89e50518eea4e7f9b Mon Sep 17 00:00:00 2001 From: Edy Silva Date: Sat, 26 Apr 2025 14:59:19 -0300 Subject: [PATCH 1/3] src: improve parsing of boolean options --- src/node_config_file.cc | 8 ++++++-- test/fixtures/rc/inspect-false.json | 5 +++++ test/fixtures/rc/inspect-true.json | 5 +++++ test/parallel/test-config-file.js | 26 ++++++++++++++++++++++++++ 4 files changed, 42 insertions(+), 2 deletions(-) create mode 100644 test/fixtures/rc/inspect-false.json create mode 100644 test/fixtures/rc/inspect-true.json diff --git a/src/node_config_file.cc b/src/node_config_file.cc index d801d935a41706..e697002ae1a2e0 100644 --- a/src/node_config_file.cc +++ b/src/node_config_file.cc @@ -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 diff --git a/test/fixtures/rc/inspect-false.json b/test/fixtures/rc/inspect-false.json new file mode 100644 index 00000000000000..32bb5961f24d0d --- /dev/null +++ b/test/fixtures/rc/inspect-false.json @@ -0,0 +1,5 @@ +{ + "nodeOptions": { + "inspect": false + } +} diff --git a/test/fixtures/rc/inspect-true.json b/test/fixtures/rc/inspect-true.json new file mode 100644 index 00000000000000..684571a5a691a2 --- /dev/null +++ b/test/fixtures/rc/inspect-true.json @@ -0,0 +1,5 @@ +{ + "nodeOptions": { + "inspect": true + } +} diff --git a/test/parallel/test-config-file.js b/test/parallel/test-config-file.js index 2154fd37c692c8..4b3737217f684d 100644 --- a/test/parallel/test-config-file.js +++ b/test/parallel/test-config-file.js @@ -232,6 +232,32 @@ 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', + '--expose-internals', + '--experimental-config-file', + fixtures.path('rc/inspect-true.json'), + '-p', 'require("internal/options").getOptionValue("--inspect")', + ]); + match(result.stderr, /^Debugger listening on (ws:\/\/[^\s]+)/); + strictEqual(result.stdout, 'true\n'); + strictEqual(result.code, 0); +}); + +test('--inspect=false should be parsed correctly', { skip: !process.features.inspector }, async () => { + const result = await spawnPromisified(process.execPath, [ + '--no-warnings', + '--expose-internals', + '--experimental-config-file', + fixtures.path('rc/inspect-false.json'), + '-p', 'require("internal/options").getOptionValue("--inspect")', + ]); + strictEqual(result.stderr, ''); + strictEqual(result.stdout, 'false\n'); + strictEqual(result.code, 0); +}); + test('no op flag should throw', async () => { const result = await spawnPromisified(process.execPath, [ '--no-warnings', From 46c258859eb3edffe4e416461702f1642daa0a32 Mon Sep 17 00:00:00 2001 From: Edy Silva Date: Wed, 30 Apr 2025 12:19:24 -0300 Subject: [PATCH 2/3] test: update test --- test/parallel/test-config-file.js | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/test/parallel/test-config-file.js b/test/parallel/test-config-file.js index 4b3737217f684d..b4edc564b36306 100644 --- a/test/parallel/test-config-file.js +++ b/test/parallel/test-config-file.js @@ -235,13 +235,12 @@ test('host port flag should be parsed correctly', { skip: !process.features.insp test('--inspect=true should be parsed correctly', { skip: !process.features.inspector }, async () => { const result = await spawnPromisified(process.execPath, [ '--no-warnings', - '--expose-internals', '--experimental-config-file', fixtures.path('rc/inspect-true.json'), - '-p', 'require("internal/options").getOptionValue("--inspect")', + '-p', 'require("node:inspector").url()', ]); match(result.stderr, /^Debugger listening on (ws:\/\/[^\s]+)/); - strictEqual(result.stdout, 'true\n'); + match(result.stdout, /ws:\/\/[^\s]+/); strictEqual(result.code, 0); }); @@ -251,10 +250,10 @@ test('--inspect=false should be parsed correctly', { skip: !process.features.ins '--expose-internals', '--experimental-config-file', fixtures.path('rc/inspect-false.json'), - '-p', 'require("internal/options").getOptionValue("--inspect")', + '-p', 'require("node:inspector").url()', ]); strictEqual(result.stderr, ''); - strictEqual(result.stdout, 'false\n'); + strictEqual(result.stdout, 'undefined\n'); strictEqual(result.code, 0); }); From 71d8cfc3a6c3a4983cd3a5e6b2c4a5f701e7c499 Mon Sep 17 00:00:00 2001 From: Edy Silva Date: Wed, 30 Apr 2025 12:36:31 -0300 Subject: [PATCH 3/3] fixup: remove unneeded flag Co-authored-by: Marco Ippolito --- test/parallel/test-config-file.js | 1 - 1 file changed, 1 deletion(-) diff --git a/test/parallel/test-config-file.js b/test/parallel/test-config-file.js index b4edc564b36306..0ac24fad512c9a 100644 --- a/test/parallel/test-config-file.js +++ b/test/parallel/test-config-file.js @@ -247,7 +247,6 @@ test('--inspect=true should be parsed correctly', { skip: !process.features.insp test('--inspect=false should be parsed correctly', { skip: !process.features.inspector }, async () => { const result = await spawnPromisified(process.execPath, [ '--no-warnings', - '--expose-internals', '--experimental-config-file', fixtures.path('rc/inspect-false.json'), '-p', 'require("node:inspector").url()',