Skip to content

fix: decodeBool should handle float and string in weakly typed mode#2809

Open
beck-8 wants to merge 1 commit into
MetaCubeX:Alphafrom
beck-8:fix-decodebool-weaktype
Open

fix: decodeBool should handle float and string in weakly typed mode#2809
beck-8 wants to merge 1 commit into
MetaCubeX:Alphafrom
beck-8:fix-decodebool-weaktype

Conversation

@beck-8

@beck-8 beck-8 commented May 20, 2026

Copy link
Copy Markdown

Summary

structure.decodeBool only accepts bool/int/uint, while its sibling decoders decodeInt, decodeUint and decodeFloat all additionally handle float and string (incl. json.Number, whose reflect.Kind is String) under WeaklyTypedInput.

As a result, a bool plugin option such as mux: 1 decodes fine when the value arrives as int (plain YAML), but fails with expected type 'bool', got unconvertible type 'json.Number' / 'float64' when the config is parsed by a JSON decoder — e.g. an embedder that calls json.Decoder.UseNumber() before handing the proxy maps to adapter.ParseProxy.

This patch adds the missing float and string branches so decodeBool is consistent with the other numeric decoders:

  • float!= 0
  • stringstrconv.ParseBool, falling back to strconv.ParseFloat(...) != 0 so numeric strings ("0", "1", "2") keep the same != 0 semantics as the int/uint/float branches.

Test plan

  • go build ./common/structure/
  • go vet ./common/structure/
  • go test ./common/structure/

decodeBool only accepted bool/int/uint, while decodeInt/decodeUint/decodeFloat
all handle float and string (e.g. json.Number, whose kind is string) under
WeaklyTypedInput. A bool plugin-opt such as `mux: 1` fed in as float64 or
json.Number therefore failed with "unconvertible type". Add the missing float
and string branches to match the sibling decoders.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant