logxi
logxi copied to clipboard
JSONFormatter: check implemented interface before scalars
A type alias for built-in scalar types may implement the fmt.Stringer or json.Marshaler interface. However, the JSONFormatter checked for the scalar type before considering the interfaces, and then used one of the strconv functions to encode the value.
That is a) unexpected and b) doesn't necessarily produce correct JSON, leading to a panic. For instance, strconv.FormatFloat(math.Inf(1), 'g', -1, 64)
encodes to +Inf
, not "+Inf"
.