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>
diff --git a/encoding/prototext/decode.go b/encoding/prototext/decode.go
index 8fb1d9e..179d6e8 100644
--- a/encoding/prototext/decode.go
+++ b/encoding/prototext/decode.go
@@ -744,9 +744,6 @@
 				// 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
-				}
 			}
 		}
 	}
diff --git a/encoding/prototext/decode_test.go b/encoding/prototext/decode_test.go
index 441dcb2..2e92dd2 100644
--- a/encoding/prototext/decode_test.go
+++ b/encoding/prototext/decode_test.go
@@ -226,6 +226,17 @@
 		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},
 		inputMessage: &pb3.Scalars{},