Skip to content

Commit 858aec2

Browse files
committed
Fix false booleans in config file being parsed as true
Options like `enable-remote-storage: false` in config.yaml are converted to `--enable-remote-storage=false`, but the parser set any boolean option to true regardless of its value. Booleans set to false are now ignored, the same way optional strings set to false already are. Fixes #8049
1 parent 41cf6f7 commit 858aec2

2 files changed

Lines changed: 18 additions & 1 deletion

File tree

‎src/node/cli.ts‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -436,7 +436,11 @@ export const parse = (
436436

437437
const option = options[key]
438438
if (option.type === "boolean") {
439-
;(args[key] as boolean) = true
439+
// Booleans set to false (for example `--flag=false`, which is also how
440+
// false values from the config file are passed in) are ignored.
441+
if (value !== "false") {
442+
;(args[key] as boolean) = true
443+
}
440444
continue
441445
}
442446

‎test/unit/node/cli.test.ts‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -578,6 +578,19 @@ describe("parser", () => {
578578
it("should ignore optional strings set to false", async () => {
579579
expect(parse(["--cert=false"])).toEqual({})
580580
})
581+
it("should ignore booleans set to false", async () => {
582+
expect(parse(["--disable-telemetry=false"])).toEqual({})
583+
})
584+
it("should parse booleans set to false in the config file", () => {
585+
const configContents = `
586+
disable-telemetry: false
587+
disable-update-check: true
588+
`
589+
expect(parseConfigFile(configContents, "/fake-config-path")).toEqual({
590+
config: "/fake-config-path",
591+
"disable-update-check": true,
592+
})
593+
})
581594
it("should use last flag", async () => {
582595
expect(parse(["--port", "8081", "--port", "8082"])).toEqual({
583596
port: 8082,

0 commit comments

Comments
 (0)