From ef89c2fac96d9c337bc8a1019ae139bcd8e6558d Mon Sep 17 00:00:00 2001 From: Edy Silva Date: Sun, 20 Jul 2025 01:47:16 -0300 Subject: [PATCH] src,test: fix config file parsing for flags defaulted to true MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit PR-URL: https://github.com/nodejs/node/pull/59110 Reviewed-By: Pietro Marchini Reviewed-By: Marco Ippolito Reviewed-By: Jacob Smith Reviewed-By: Luigi Pinca Reviewed-By: Michaƫl Zasso --- src/node_config_file.cc | 4 ++++ test/fixtures/rc/warnings-false.json | 5 +++++ test/parallel/test-config-file.js | 11 +++++++++++ 3 files changed, 20 insertions(+) create mode 100644 test/fixtures/rc/warnings-false.json diff --git a/src/node_config_file.cc b/src/node_config_file.cc index 1a19465c728..e6c049b4d14 100644 --- a/src/node_config_file.cc +++ b/src/node_config_file.cc @@ -55,6 +55,10 @@ ParseResult ConfigReader::ProcessOptionValue( if (result) { // If the value is true, we need to set the flag output->push_back(option_name); + } else { + // Ensure negation is made putting the "--no-" prefix + output->push_back("--no-" + + option_name.substr(2, option_name.size() - 2)); } break; diff --git a/test/fixtures/rc/warnings-false.json b/test/fixtures/rc/warnings-false.json new file mode 100644 index 00000000000..55ca24aac3a --- /dev/null +++ b/test/fixtures/rc/warnings-false.json @@ -0,0 +1,5 @@ +{ + "nodeOptions": { + "warnings": false + } +} diff --git a/test/parallel/test-config-file.js b/test/parallel/test-config-file.js index 75d0922630c..cc235bfadae 100644 --- a/test/parallel/test-config-file.js +++ b/test/parallel/test-config-file.js @@ -60,6 +60,17 @@ test('should parse boolean flag', async () => { strictEqual(result.code, 0); }); +test('should parse boolean flag defaulted to true', async () => { + const result = await spawnPromisified(process.execPath, [ + '--experimental-config-file', + fixtures.path('rc/warnings-false.json'), + '-p', 'process.emitWarning("A warning")', + ]); + strictEqual(result.stderr, ''); + strictEqual(result.stdout, 'undefined\n'); + strictEqual(result.code, 0); +}); + test('should throw an error when a flag is declared twice', async () => { const result = await spawnPromisified(process.execPath, [ '--no-warnings',