Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: add check for repeated google.protobuf.Any type #3080

Merged
merged 17 commits into from Dec 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion runtime/fieldmask.go
Expand Up @@ -64,7 +64,7 @@ func FieldMaskFromRequestBody(r io.Reader, msg proto.Message) (*field_mask.Field
continue
}

if isProtobufAnyMessage(fd.Message()) {
if isProtobufAnyMessage(fd.Message()) && !fd.IsList() {
_, hasTypeField := v.(map[string]interface{})["@type"]
if hasTypeField {
queue = append(queue, fieldMaskPathItem{path: k})
Expand Down
7 changes: 6 additions & 1 deletion runtime/fieldmask_test.go
Expand Up @@ -165,13 +165,18 @@ func TestFieldMaskFromRequestBody(t *testing.T) {
"nested",
),
},

{
name: "protobuf-any",
msg: &examplepb.ABitOfEverything{},
input: `{"anytype":{"@type": "xx.xx/examplepb.NestedOuter", "one":{"two":{"three":{"a":true, "b":false}}}}}`,
expected: newFieldMask("anytype"), //going deeper makes no sense
},
{
name: "repeated-protobuf-any",
msg: &examplepb.ABitOfEverything{},
input: `{"repeated_anytype":[{"@type": "xx.xx/examplepb.NestedOuter", "one":{"two":{"three":{"a":true, "b":false}}}}]}`,
expected: newFieldMask("repeated_anytype"), //going deeper makes no sense
},
} {
t.Run(tc.name, func(t *testing.T) {
actual, err := FieldMaskFromRequestBody(bytes.NewReader([]byte(tc.input)), tc.msg)
Expand Down