Skip to content

Commit

Permalink
encode: don't capitalize inf
Browse files Browse the repository at this point in the history
  • Loading branch information
pelletier committed Apr 10, 2022
1 parent 5a3f3aa commit b8cc6dc
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
9 changes: 8 additions & 1 deletion marshaler.go
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,10 @@ func (enc *Encoder) encode(b []byte, ctx encoderCtx, v reflect.Value) ([]byte, e

if math.IsNaN(f) {
b = append(b, "nan"...)
} else if f > math.MaxFloat32 {
b = append(b, "inf"...)
} else if f < -math.MaxFloat32 {
b = append(b, "-inf"...)
} else if math.Trunc(f) == f {
b = strconv.AppendFloat(b, f, 'f', 1, 32)
} else {
Expand All @@ -282,7 +286,10 @@ func (enc *Encoder) encode(b []byte, ctx encoderCtx, v reflect.Value) ([]byte, e
f := v.Float()
if math.IsNaN(f) {
b = append(b, "nan"...)

} else if f > math.MaxFloat64 {
b = append(b, "inf"...)
} else if f < -math.MaxFloat64 {
b = append(b, "-inf"...)
} else if math.Trunc(f) == f {
b = strconv.AppendFloat(b, f, 'f', 1, 64)
} else {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
go test fuzz v1
[]byte("0=inf")

0 comments on commit b8cc6dc

Please sign in to comment.