From 99ef802c0031af7d0e3313cda60b6fac8471ac06 Mon Sep 17 00:00:00 2001 From: Edy Silva Date: Fri, 18 Jul 2025 01:39:07 -0300 Subject: [PATCH] src,test: fix config file parsing for flags defaulted to true --- 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 1a19465c728ebc..e6c049b4d14f10 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 00000000000000..55ca24aac3a503 --- /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 75d0922630cd3a..cc235bfadae146 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',