Browse Source

make colons optional in text parser. (missed update in google-internal code)
add test.

R=dsymonds, dsymonds1
http://codereview.appspot.com/1733042

Rob Pike 15 years ago
parent
commit
aaf695ae99
2 changed files with 24 additions and 7 deletions
  1. 10 7
      proto/text_parser.go
  2. 14 0
      proto/text_parser_test.go

+ 10 - 7
proto/text_parser.go

@@ -304,13 +304,16 @@ func (p *textParser) readStruct(sv *reflect.StructValue, terminator string) *Par
 				// those three become *T, *string and []T respectively, so we can check for
 				// this field being a pointer to a non-string.
 				typ := st.Field(fi).Type
-				pt, ok := typ.(*reflect.PtrType)
-				if !ok {
-					break
-				}
-				_, ok = pt.Elem().(*reflect.StringType)
-				if ok {
-					break
+				if pt, ok := typ.(*reflect.PtrType); ok {
+					// *T or *string
+					if _, ok := pt.Elem().(*reflect.StringType); ok {
+						break
+					}
+				} else if st, ok := typ.(*reflect.SliceType); ok {
+					// []T or []*T
+					if _, ok := st.Elem().(*reflect.PtrType); !ok {
+						break
+					}
 				}
 				needColon = false
 			}

+ 14 - 0
proto/text_parser_test.go

@@ -132,6 +132,20 @@ var unMarshalTextTests = []UnmarshalTextTest{
 		},
 	},
 
+	// Repeated message with/without colon and <>/{}
+	UnmarshalTextTest{
+		in: `count:42 others:{} others{} others:<> others:{}`,
+		out: &MyMessage{
+			Count: Int32(42),
+			Others: []*OtherMessage{
+				&OtherMessage{},
+				&OtherMessage{},
+				&OtherMessage{},
+				&OtherMessage{},
+			},
+		},
+	},
+
 	// Missing colon for inner message
 	UnmarshalTextTest{
 		in: `count:42 inner < host: "cauchy.syd" >`,