Go: encoding/json: panics on NaN map keys

Created on 16 Dec 2020  路  4Comments  路  Source: golang/go

Using go1.16

Reproduction:
```go
type F64 float64

func (f F64) MarshalText() ([]byte, error) {
return []byte(fmt.Sprint(f)), nil
}

func main() {
m := map[F64]string{F64(math.NaN()): "NaN"}
json.Marshal(m)
}
````

Panics with panic: reflect: call of reflect.Value.Type on zero Value

NeedsFix help wanted

Most helpful comment

More precisely: NaN ~keys~ are trouble.

All 4 comments

Change https://golang.org/cl/278632 mentions this issue: encoding/json: fix invalid kind reflect type

See previously #14427, #24075, #20660. (NaN keys are trouble!)

More precisely: NaN ~keys~ are trouble.

More precisely: NaN ~keys~ are trouble.

Float as key is unsuppored, however this bug is about marhsal maps with interface MarshalText :)

Was this page helpful?
0 / 5 - 0 ratings