]> Cypherpunks repositories - gostls13.git/commit
encoding/json: fix panic for nil instances of TextMarshaler in map keys
authorWilliam Poussier <william.poussier@gmail.com>
Sun, 1 Sep 2019 15:38:31 +0000 (15:38 +0000)
committerDaniel Martí <mvdan@mvdan.cc>
Sun, 1 Sep 2019 16:39:38 +0000 (16:39 +0000)
commit85f3ca74882703042bcc2f17353eda192d649920
treedea4723907834da268ad386eec3c104a266fa336
parenta806c213e7dd32520d204890fb953c8e9d1142f2
encoding/json: fix panic for nil instances of TextMarshaler in map keys

This change adds a a check in the encodeWithString.resolve method
to ensure that a reflect.Value with kind Ptr is not nil before
the type assertion to TextMarshaler.

If the value is nil, the method returns a nil error, and the map key
encodes to an empty string.

Fixes #33675

Change-Id: I0a04cf690ae67006f6a9c5f8cbb4cc99d236bca8
GitHub-Last-Rev: 6c987c90846f854e21814dbfb3a073605ec8a94c
GitHub-Pull-Request: golang/go#33700
Reviewed-on: https://go-review.googlesource.com/c/go/+/190697
Run-TryBot: Daniel Martí <mvdan@mvdan.cc>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Daniel Martí <mvdan@mvdan.cc>
src/encoding/json/encode.go
src/encoding/json/encode_test.go