]> Cypherpunks repositories - gostls13.git/commit
encoding/json: marshal maps using reflect.Value.MapRange
authorMeng Zhuo <mzh@golangcn.org>
Thu, 21 Jan 2021 14:53:30 +0000 (22:53 +0800)
committerMeng Zhuo <mzh@golangcn.org>
Fri, 5 Mar 2021 02:28:11 +0000 (02:28 +0000)
commita7526bbf72dfe0fde00d88f85fd6cddccdb3a345
tree29a64a551a3639c9ce42a99a59a8e825bc340342
parent96a96a9058004af531db56dee26d82af08321cdb
encoding/json: marshal maps using reflect.Value.MapRange

Map serialization using reflect.Value.MapIndex cannot retrieve
map keys that contain a NaN, resulting in a panic.
Switch the implementation to use the reflect.Value.MapRange method
instead, which iterates over all map entries regardless of whether
they are directly retrievable.

Note that according to RFC 8259, section 4, a JSON object should
have unique names, but does not forbid the occurrence of duplicate names.

Fixes #43207

Change-Id: If4bc55229b1f64b8ca4b0fed37549725efdace39
Reviewed-on: https://go-review.googlesource.com/c/go/+/278632
Trust: Meng Zhuo <mzh@golangcn.org>
Trust: Joe Tsai <thebrokentoaster@gmail.com>
Trust: Bryan C. Mills <bcmills@google.com>
Run-TryBot: Meng Zhuo <mzh@golangcn.org>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Joe Tsai <thebrokentoaster@gmail.com>
Reviewed-by: Daniel Martí <mvdan@mvdan.cc>
src/encoding/json/encode.go
src/encoding/json/encode_test.go