logxi icon indicating copy to clipboard operation
logxi copied to clipboard

JSONFormatter: check implemented interface before scalars

Open pschultz opened this issue 7 years ago • 0 comments

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".

pschultz avatar Sep 15 '16 15:09 pschultz