make colons optional in text parser. (missed update in google-internal code)
add test.
R=dsymonds, dsymonds1
http://codereview.appspot.com/1733042
diff --git a/proto/text_parser.go b/proto/text_parser.go
index f888f9b..4c0166f 100644
--- a/proto/text_parser.go
+++ b/proto/text_parser.go
@@ -304,13 +304,16 @@
// 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
}
diff --git a/proto/text_parser_test.go b/proto/text_parser_test.go
index 96ec965..5382ac5 100644
--- a/proto/text_parser_test.go
+++ b/proto/text_parser_test.go
@@ -132,6 +132,20 @@
},
},
+ // 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" >`,