aboutsummaryrefslogtreecommitdiff
path: root/src/encoding/json/encode_test.go
diff options
context:
space:
mode:
authorJoe Tsai <joetsai@digital-static.net>2017-11-09 20:14:47 -0800
committerJoe Tsai <thebrokentoaster@gmail.com>2017-11-13 18:23:38 +0000
commit0cee4b7b780053425a24219866b894a46b1cfd5f (patch)
tree0beedb58dee58c15e132f471f16d29a9cbef3950 /src/encoding/json/encode_test.go
parent510327012bd42aca3deac989e2e109dc71bb4605 (diff)
downloadgo-0cee4b7b780053425a24219866b894a46b1cfd5f.tar.xz
encoding/json: always ignore embedded pointers to unexported struct types
CL 60410 fixes a bug in reflect that allows assignments to an embedded field of a pointer to an unexported struct type. This breaks the json package because unmarshal is now unable to assign a newly allocated struct to such fields. In order to be consistent in the behavior for marshal and unmarshal, this CL changes both marshal and unmarshal to always ignore embedded pointers to unexported structs. Fixes #21357 Change-Id: If62ea11155555e61115ebb9cfa5305caf101bde5 Reviewed-on: https://go-review.googlesource.com/76851 Run-TryBot: Joe Tsai <thebrokentoaster@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
Diffstat (limited to 'src/encoding/json/encode_test.go')
-rw-r--r--src/encoding/json/encode_test.go7
1 files changed, 4 insertions, 3 deletions
diff --git a/src/encoding/json/encode_test.go b/src/encoding/json/encode_test.go
index 0f194e13d2..df7338c98d 100644
--- a/src/encoding/json/encode_test.go
+++ b/src/encoding/json/encode_test.go
@@ -364,8 +364,9 @@ func TestAnonymousFields(t *testing.T) {
want: `{"X":2,"Y":4}`,
}, {
// Exported fields of pointers to embedded structs should have their
- // exported fields be serialized regardless of whether the struct types
- // themselves are exported.
+ // exported fields be serialized only for exported struct types.
+ // Pointers to unexported structs are not allowed since the decoder
+ // is unable to allocate a struct for that field
label: "EmbeddedStructPointer",
makeInput: func() interface{} {
type (
@@ -378,7 +379,7 @@ func TestAnonymousFields(t *testing.T) {
)
return S{&s1{1, 2}, &S2{3, 4}}
},
- want: `{"X":2,"Y":4}`,
+ want: `{"Y":4}`,
}, {
// Exported fields on embedded unexported structs at multiple levels
// of nesting should still be serialized.