fix: decodeBool should handle float and string in weakly typed mode#2809
Open
beck-8 wants to merge 1 commit into
Open
fix: decodeBool should handle float and string in weakly typed mode#2809beck-8 wants to merge 1 commit into
beck-8 wants to merge 1 commit into
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
structure.decodeBoolonly acceptsbool/int/uint, while its sibling decodersdecodeInt,decodeUintanddecodeFloatall additionally handlefloatandstring(incl.json.Number, whosereflect.KindisString) underWeaklyTypedInput.As a result, a
boolplugin option such asmux: 1decodes fine when the value arrives asint(plain YAML), but fails withexpected type 'bool', got unconvertible type 'json.Number'/'float64'when the config is parsed by a JSON decoder — e.g. an embedder that callsjson.Decoder.UseNumber()before handing the proxy maps toadapter.ParseProxy.This patch adds the missing
floatandstringbranches sodecodeBoolis consistent with the other numeric decoders:float→!= 0string→strconv.ParseBool, falling back tostrconv.ParseFloat(...) != 0so numeric strings ("0","1","2") keep the same!= 0semantics as the int/uint/float branches.Test plan
go build ./common/structure/go vet ./common/structure/go test ./common/structure/