encoding/prototext: fix skipping of unknown fields

Inside decoder.skipValue we should not be calling skipValue again
since we had already read the value earlier. The only possible
composite type in the context of a list is another message,
which is already handled in the case above.

Change-Id: If40da2d369e0a64a64ba9b961377331231158fe2
Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/317430
Trust: Joe Tsai <joetsai@digital-static.net>
Trust: Herbie Ong <herbie@google.com>
Reviewed-by: Herbie Ong <herbie@google.com>
This commit is contained in:
Joe Tsai 2021-05-05 15:13:31 -07:00
parent fb30439f55
commit c30776bb3b
2 changed files with 11 additions and 3 deletions

View File

@ -744,9 +744,6 @@ func (d decoder) skipValue() error {
// Skip items. This will not validate whether skipped values are
// of the same type or not, same behavior as C++
// TextFormat::Parser::AllowUnknownField(true) version 3.8.0.
if err := d.skipValue(); err != nil {
return err
}
}
}
}

View File

@ -225,6 +225,17 @@ s_string: "谷歌"
inputMessage: &pb2.Scalars{},
inputText: `13:"hello"`,
wantErr: "cannot specify field by number",
}, {
desc: "unknown list field",
umo: prototext.UnmarshalOptions{DiscardUnknown: true},
inputMessage: &pb2.Scalars{},
inputText: `unknown_field: { strings: [ "" ] }`,
}, {
desc: "unknown list of list field",
umo: prototext.UnmarshalOptions{DiscardUnknown: true},
inputMessage: &pb2.Scalars{},
inputText: `unknown_field: { strings: [ [ ] ] }`,
wantErr: `(line 1:29): invalid scalar value: [`,
}, {
desc: "proto3 message cannot parse field number",
umo: prototext.UnmarshalOptions{DiscardUnknown: true},