Skip to content

Commit 7542c08

Browse files
veithrenovate[bot]johanbrandhorst
authored
fix: add check for repeated google.protobuf.Any type (#3080)
* 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 <[email protected]>
1 parent acba3f5 commit 7542c08

File tree

4 files changed

+146
-127
lines changed

4 files changed

+146
-127
lines changed

runtime/fieldmask.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ func FieldMaskFromRequestBody(r io.Reader, msg proto.Message) (*field_mask.Field
6464
continue
6565
}
6666

67-
if isProtobufAnyMessage(fd.Message()) {
67+
if isProtobufAnyMessage(fd.Message()) && !fd.IsList() {
6868
_, hasTypeField := v.(map[string]interface{})["@type"]
6969
if hasTypeField {
7070
queue = append(queue, fieldMaskPathItem{path: k})

runtime/fieldmask_test.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,13 +165,18 @@ func TestFieldMaskFromRequestBody(t *testing.T) {
165165
"nested",
166166
),
167167
},
168-
169168
{
170169
name: "protobuf-any",
171170
msg: &examplepb.ABitOfEverything{},
172171
input: `{"anytype":{"@type": "xx.xx/examplepb.NestedOuter", "one":{"two":{"three":{"a":true, "b":false}}}}}`,
173172
expected: newFieldMask("anytype"), //going deeper makes no sense
174173
},
174+
{
175+
name: "repeated-protobuf-any",
176+
msg: &examplepb.ABitOfEverything{},
177+
input: `{"repeated_anytype":[{"@type": "xx.xx/examplepb.NestedOuter", "one":{"two":{"three":{"a":true, "b":false}}}}]}`,
178+
expected: newFieldMask("repeated_anytype"), //going deeper makes no sense
179+
},
175180
} {
176181
t.Run(tc.name, func(t *testing.T) {
177182
actual, err := FieldMaskFromRequestBody(bytes.NewReader([]byte(tc.input)), tc.msg)

0 commit comments

Comments
 (0)