GeezerVison is showing github.com — src: improve parsing of boolean options · nodejs/node@130eaa2
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: src/node_config_file.cc +6-2Lines changed: 6 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -59,8 +59,12 @@ ParseResult ConfigReader::ParseNodeOptions( | 59 | 59 | FPrintF(stderr, "Invalid value for %s\n", it->first.c_str()); | 60 | 60 | return ParseResult::InvalidContent; | 61 | 61 | } | 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 | + | 64 | 68 | break; | 65 | 69 | } | 66 | 70 | // String array can allow both string and array types | |
Collapse file Copy file name to clipboard +5Lines changed: 5 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| | 1 | +{ | | 2 | + "nodeOptions": { | | 3 | + "inspect": false | | 4 | + } | | 5 | +} |
Collapse file Copy file name to clipboard +5Lines changed: 5 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| | 1 | +{ | | 2 | + "nodeOptions": { | | 3 | + "inspect": true | | 4 | + } | | 5 | +} |
Collapse file Copy file name to clipboardExpand all lines: test/parallel/test-config-file.js +24Lines changed: 24 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -232,6 +232,30 @@ test('host port flag should be parsed correctly', { skip: !process.features.insp | 232 | 232 | strictEqual(result.code, 0); | 233 | 233 | }); | 234 | 234 |
| | 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 | + | 235 | 259 | test('no op flag should throw', async () => { | 236 | 260 | const result = await spawnPromisified(process.execPath, [ | 237 | 261 | '--no-warnings', | |
|