diff --git a/encoding/prototext/decode_test.go b/encoding/prototext/decode_test.go index e7e7faeb..be6e5a4f 100644 --- a/encoding/prototext/decode_test.go +++ b/encoding/prototext/decode_test.go @@ -657,12 +657,16 @@ delimited_field {} desc: "group field name", inputMessage: &pb2.Nests{}, inputText: `optgroup: {}`, - wantErr: "unknown field: optgroup", + wantMessage: &pb2.Nests{ + Optgroup: &pb2.Nests_OptGroup{}, + }, }, { - desc: "delimited encoded group-line message field name", + desc: "delimited encoded group-like message field name", inputMessage: &pbeditions.Nests{}, - inputText: `optgroup: {}`, - wantErr: "unknown field: optgroup", + inputText: `optgroup {}`, + wantMessage: &pbeditions.Nests{ + Optgroup: &pbeditions.Nests_OptGroup{}, + }, }, { desc: "delimited encoded message field name", inputMessage: &pbeditions.Nests{}, diff --git a/internal/cmd/generate-types/main.go b/internal/cmd/generate-types/main.go index 9a7460c9..76e3b894 100644 --- a/internal/cmd/generate-types/main.go +++ b/internal/cmd/generate-types/main.go @@ -171,6 +171,16 @@ var descListTypesTemplate = template.Must(template.New("").Parse(` if _, ok := p.byText[d.TextName()]; !ok { p.byText[d.TextName()] = d } + if isGroupLike(d) { + lowerJSONName := strings.ToLower(d.JSONName()) + if _, ok := p.byJSON[lowerJSONName]; !ok { + p.byJSON[lowerJSONName] = d + } + lowerTextName := strings.ToLower(d.TextName()) + if _, ok := p.byText[lowerTextName]; !ok { + p.byText[lowerTextName] = d + } + } {{- end}} {{- if .NumberExpr}} if _, ok := p.byNum[d.Number()]; !ok { @@ -200,6 +210,7 @@ func writeSource(file, src string) { "fmt", "math", "reflect", + "strings", "sync", "unicode/utf8", "", diff --git a/internal/conformance/failing_tests_text_format.txt b/internal/conformance/failing_tests_text_format.txt index c4335e84..c4ba1b9a 100644 --- a/internal/conformance/failing_tests_text_format.txt +++ b/internal/conformance/failing_tests_text_format.txt @@ -8,13 +8,3 @@ Recommended.Proto3.TextFormatInput.StringLiteralShortUnicodeEscapeSurrogatePairB Recommended.Proto3.TextFormatInput.StringLiteralShortUnicodeEscapeSurrogatePairString Recommended.Proto3.TextFormatInput.StringLiteralUnicodeEscapeSurrogatePairLongShortBytes Recommended.Proto3.TextFormatInput.StringLiteralUnicodeEscapeSurrogatePairLongShortString -Required.Editions.TextFormatInput.DelimitedFieldLowercased.ProtobufOutput -Required.Editions.TextFormatInput.DelimitedFieldLowercased.TextFormatOutput -Required.Editions_Proto2.TextFormatInput.GroupFieldLowercased.ProtobufOutput -Required.Editions_Proto2.TextFormatInput.GroupFieldLowercased.TextFormatOutput -Required.Editions_Proto2.TextFormatInput.GroupFieldLowercasedMultiWord.ProtobufOutput -Required.Editions_Proto2.TextFormatInput.GroupFieldLowercasedMultiWord.TextFormatOutput -Required.Proto2.TextFormatInput.GroupFieldLowercased.ProtobufOutput -Required.Proto2.TextFormatInput.GroupFieldLowercased.TextFormatOutput -Required.Proto2.TextFormatInput.GroupFieldLowercasedMultiWord.ProtobufOutput -Required.Proto2.TextFormatInput.GroupFieldLowercasedMultiWord.TextFormatOutput diff --git a/internal/filedesc/desc_list_gen.go b/internal/filedesc/desc_list_gen.go index 30db19fd..f4107c05 100644 --- a/internal/filedesc/desc_list_gen.go +++ b/internal/filedesc/desc_list_gen.go @@ -8,6 +8,7 @@ package filedesc import ( "fmt" + "strings" "sync" "google.golang.org/protobuf/internal/descfmt" @@ -198,6 +199,16 @@ func (p *Fields) lazyInit() *Fields { if _, ok := p.byText[d.TextName()]; !ok { p.byText[d.TextName()] = d } + if isGroupLike(d) { + lowerJSONName := strings.ToLower(d.JSONName()) + if _, ok := p.byJSON[lowerJSONName]; !ok { + p.byJSON[lowerJSONName] = d + } + lowerTextName := strings.ToLower(d.TextName()) + if _, ok := p.byText[lowerTextName]; !ok { + p.byText[lowerTextName] = d + } + } if _, ok := p.byNum[d.Number()]; !ok { p.byNum[d.Number()] = d }