Skip to content

Commit

Permalink
fix: add check for repeated google.protobuf.Any type (#3080)
Browse files Browse the repository at this point in the history
* test type any

* feat: Patcher for type google.protobuf.Any

* feat: Patcher for type google.protobuf.Any

* feat: Patcher for type google.protobuf.Any

* fix: add propper error message if someone sends only parts of a google.protobuf.Any message

* revert

* Rerun generation

* Rerun Bazel generation too

* fix: add check for repeated google.protobuf.Any type for generating fieldmask paths.

* fix: add check for repeated google.protobuf.Any type for generating fieldmask paths.

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: Johan Brandhorst <johan.brandhorst@gmail.com>
  • Loading branch information
3 people committed Dec 21, 2022
1 parent acba3f5 commit 7542c08
Show file tree
Hide file tree
Showing 4 changed files with 146 additions and 127 deletions.
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

0 comments on commit 7542c08

Please sign in to comment.