diff --git a/cli/options.go b/cli/options.go index 78fc0f0..afd0a4e 100644 --- a/cli/options.go +++ b/cli/options.go @@ -38,8 +38,11 @@ var boolWords = map[string]bool{ } // boolWord reports a value's truth and whether it is a recognised boolean word. +// Whitespace is trimmed (aria2 strips config values too), but case is +// significant: aria2 rejects "True"/"TRUE", so the match is against exactly +// "true"/"false". func boolWord(s string) (val, ok bool) { - val, ok = boolWords[strings.ToLower(strings.TrimSpace(s))] + val, ok = boolWords[strings.TrimSpace(s)] return val, ok } diff --git a/cli/parse_test.go b/cli/parse_test.go index caeaea3..f359e0f 100644 --- a/cli/parse_test.go +++ b/cli/parse_test.go @@ -139,14 +139,16 @@ func TestValidateFloatNonNegative(t *testing.T) { func TestValidateBool(t *testing.T) { b := byLong["enable-dht"] - // aria2 accepts only true/false; the invented yes/no/1/0/on/off spellings - // were removed, so they must now fail validation. - for _, ok := range []string{"true", "false"} { + // aria2 accepts only literal true/false (case-sensitive) but trims + // surrounding whitespace; match that exactly. + for _, ok := range []string{"true", "false", " true ", "false\t"} { if err := validate(b, ok); err != nil { t.Errorf("validate bool %q: %v", ok, err) } } - for _, bad := range []string{"yes", "no", "1", "0", "on", "off", "flase"} { + // The invented spellings and any case variant must now fail. + for _, bad := range []string{"yes", "no", "1", "0", "on", "off", "flase", + "True", "TRUE", "tRuE", "False", "FALSE"} { if err := validate(b, bad); err == nil { t.Errorf("validate bool %q: want error (only true/false accepted)", bad) }