mirror of
https://github.com/protocolbuffers/protobuf-go.git
synced 2025-01-29 18:32:46 +00:00
prototext: Fix parsing of unknown repeated message fields
If `DiscardUnknown` was enabled, previously this syntax was rejected with an error "unexpected token: ]": unknown_field: [ {} ] This is because the parser short-circuited after parsing the {}, and didn't handle the closing square brace. Now it no longer short-circuits. Change-Id: I6230b56766632752a5cc8822b17ed8262873d6cc Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/530616 Reviewed-by: Damien Neil <dneil@google.com> Reviewed-by: Michael Stapelberg <stapelberg@google.com>
This commit is contained in:
parent
8088bf85b8
commit
6352deccdb
@ -739,7 +739,9 @@ func (d decoder) skipValue() error {
|
||||
case text.ListClose:
|
||||
return nil
|
||||
case text.MessageOpen:
|
||||
return d.skipMessageValue()
|
||||
if err := d.skipMessageValue(); err != nil {
|
||||
return err
|
||||
}
|
||||
default:
|
||||
// Skip items. This will not validate whether skipped values are
|
||||
// of the same type or not, same behavior as C++
|
||||
|
@ -237,6 +237,11 @@ s_string: "谷歌"
|
||||
inputMessage: &pb2.Scalars{},
|
||||
inputText: `unknown_field: { strings: [ [ ] ] }`,
|
||||
wantErr: `(line 1:29): invalid scalar value: [`,
|
||||
}, {
|
||||
desc: "unknown list of message field",
|
||||
umo: prototext.UnmarshalOptions{DiscardUnknown: true},
|
||||
inputMessage: &pb2.Scalars{},
|
||||
inputText: `unknown_field: [ { a: "b" }, { c: "d" } ]`,
|
||||
}, {
|
||||
desc: "proto3 message cannot parse field number",
|
||||
umo: prototext.UnmarshalOptions{DiscardUnknown: true},
|
||||
|
Loading…
x
Reference in New Issue
Block a user