encoding/protojson: parse groups according to their real proto name

Ironically, the "real" protobuf name of a group is not the name
of the field descriptor, but the message descriptor.

Change-Id: I26ab546a94e934766fa6af6252cacd294442a221
Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/195780
Reviewed-by: Herbie Ong <herbie@google.com>
diff --git a/encoding/protojson/decode.go b/encoding/protojson/decode.go
index ec32c48..faa56b0 100644
--- a/encoding/protojson/decode.go
+++ b/encoding/protojson/decode.go
@@ -190,6 +190,16 @@
 			fd = fieldDescs.ByJSONName(name)
 			if fd == nil {
 				fd = fieldDescs.ByName(pref.Name(name))
+				if fd == nil {
+					// The proto name of a group field is in all lowercase,
+					// while the textual field name is the group message name.
+					gd := fieldDescs.ByName(pref.Name(strings.ToLower(name)))
+					if gd != nil && gd.Kind() == pref.GroupKind && gd.Message().Name() == pref.Name(name) {
+						fd = gd
+					}
+				} else if fd.Kind() == pref.GroupKind && fd.Message().Name() != pref.Name(name) {
+					fd = nil // reset since field name is actually the message name
+				}
 			}
 			if fd != nil && fd.IsWeak() && fd.Message().IsPlaceholder() {
 				fd = nil // reset since the weak reference is not linked in