mirror of
https://github.com/protocolbuffers/protobuf-go.git
synced 2025-01-29 18:32:46 +00:00
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:
parent
fb30439f55
commit
c30776bb3b
@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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},
|
||||
|
Loading…
x
Reference in New Issue
Block a user