aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Symonds <dsymonds@golang.org>2012-12-06 15:20:41 +1100
committerDavid Symonds <dsymonds@golang.org>2012-12-06 15:20:41 +1100
commitbe02a4a20fa460d8c68e31df9d6df1906abe6255 (patch)
tree1f7a28e665d8abdd8d224b51377068fad99f8a95
parentdf583ae96e600b29b3ad85a2a3a0de4c34726b13 (diff)
downloadprotobuf-be02a4a20fa460d8c68e31df9d6df1906abe6255.tar.gz
goprotobuf: Text parsing compatibility fixes:
- accept semicolon and comma after fields - accept "inf" and "-inf" for float fields R=iant CC=golang-dev https://codereview.appspot.com/6885045
-rw-r--r--proto/size_test.go2
-rw-r--r--proto/testdata/test.proto2
-rw-r--r--proto/text_parser.go16
3 files changed, 17 insertions, 3 deletions
diff --git a/proto/size_test.go b/proto/size_test.go
index 6774d39..9c60e4f 100644
--- a/proto/size_test.go
+++ b/proto/size_test.go
@@ -40,6 +40,8 @@ import (
)
var messageWithExtension1 = &pb.MyMessage{Count: Int32(7)}
+
+// messageWithExtension2 is in equal_test.go.
var messageWithExtension3 = &pb.MyMessage{Count: Int32(8)}
func init() {
diff --git a/proto/testdata/test.proto b/proto/testdata/test.proto
index 0154940..a7f38d4 100644
--- a/proto/testdata/test.proto
+++ b/proto/testdata/test.proto
@@ -252,6 +252,8 @@ message MyMessage {
// This field becomes [][]byte in the generated code.
repeated bytes rep_bytes = 10;
+ optional double bigfloat = 11;
+
extensions 100 to max;
}
diff --git a/proto/text_parser.go b/proto/text_parser.go
index 3c79876..b4e4bc1 100644
--- a/proto/text_parser.go
+++ b/proto/text_parser.go
@@ -154,7 +154,7 @@ func (p *textParser) advance() {
p.cur.offset, p.cur.line = p.offset, p.line
p.cur.unquoted = ""
switch p.s[0] {
- case '<', '>', '{', '}', ':', '[', ']':
+ case '<', '>', '{', '}', ':', '[', ']', ';', ',':
// Single symbol
p.cur.value, p.s = p.s[0:1], p.s[1:len(p.s)]
case '"', '\'':
@@ -525,6 +525,15 @@ func (p *textParser) readStruct(sv reflect.Value, terminator string) *ParseError
reqCount--
}
}
+
+ // For backward compatibility, permit a semicolon or comma after a field.
+ tok = p.next()
+ if tok.err != nil {
+ return tok.err
+ }
+ if tok.value != ";" && tok.value != "," {
+ p.back()
+ }
}
if reqCount > 0 {
@@ -581,8 +590,9 @@ func (p *textParser) readAny(v reflect.Value, props *Properties) *ParseError {
}
case reflect.Float32, reflect.Float64:
v := tok.value
- if strings.HasSuffix(v, "f") {
- // Ignore 'f' for compatibility with output generated by C++.
+ // Ignore 'f' for compatibility with output generated by C++, but don't
+ // remove 'f' when the value is "-inf" or "inf".
+ if strings.HasSuffix(v, "f") && tok.value != "-inf" && tok.value != "inf" {
v = v[:len(v)-1]
}
if f, err := strconv.ParseFloat(v, fv.Type().Bits()); err == nil {