]> Cypherpunks repositories - gostls13.git/commit
encoding/json: fix handling of anonymous fields
authorRob Pike <r@golang.org>
Tue, 9 Apr 2013 22:00:21 +0000 (15:00 -0700)
committerRob Pike <r@golang.org>
Tue, 9 Apr 2013 22:00:21 +0000 (15:00 -0700)
commit357e37dc945885a141b48182c4606f1aac8320db
tree923f35848b8d7846324286b5d6b4e13ccad07e14
parent8691f90cc53f1ebcd27d82c71432ca873a3744ca
encoding/json: fix handling of anonymous fields
The old code was incorrect and also broken. It passed the tests by accident.
The new algorithm is:
        1) Sort the fields in order of names.
        2) For all fields with the same name, sort in increasing depth.
        3) Choose the single field with shortest depth.
If any of the fields of a given name has a tag, do the above using
tagged fields of that name only.
Fixes #5245.

R=iant
CC=golang-dev
https://golang.org/cl/8583044
src/pkg/encoding/json/decode_test.go
src/pkg/encoding/json/encode.go
src/pkg/encoding/json/encode_test.go