]> Cypherpunks repositories - gostls13.git/commitdiff
time: fix error message from Parse
authorRuss Cox <rsc@golang.org>
Mon, 4 Feb 2013 05:00:36 +0000 (00:00 -0500)
committerRuss Cox <rsc@golang.org>
Mon, 4 Feb 2013 05:00:36 +0000 (00:00 -0500)
Was incorrectly discarding the offending text in some cases.

Fixes #4493.

R=golang-dev, bradfitz
CC=golang-dev
https://golang.org/cl/7277050

src/pkg/time/format.go
src/pkg/time/time_test.go

index d9e27c1be703e3362a2cdb3878eb9c183b3a0c2d..817c79a80131667f8d497d8a9430ad20eecbdb94 100644 (file)
@@ -611,14 +611,14 @@ func skip(value, prefix string) (string, error) {
        for len(prefix) > 0 {
                if prefix[0] == ' ' {
                        if len(value) > 0 && value[0] != ' ' {
-                               return "", errBad
+                               return value, errBad
                        }
                        prefix = cutspace(prefix)
                        value = cutspace(value)
                        continue
                }
                if len(value) == 0 || value[0] != prefix[0] {
-                       return "", errBad
+                       return value, errBad
                }
                prefix = prefix[1:]
                value = value[1:]
index 583b248faaf32b13156380abf49a42a616b1390c..4b268f73d9c5bd3fd1990e772fced61fa600cb52 100644 (file)
@@ -676,6 +676,11 @@ var parseErrorTests = []ParseErrorTest{
        // issue 4502. StampNano requires exactly 9 digits of precision.
        {StampNano, "Dec  7 11:22:01.000000", `cannot parse ".000000" as ".000000000"`},
        {StampNano, "Dec  7 11:22:01.0000000000", "extra text: 0"},
+       // issue 4493. Helpful errors.
+       {RFC3339, "2006-01-02T15:04:05Z07:00", `parsing time "2006-01-02T15:04:05Z07:00": extra text: 07:00`},
+       {RFC3339, "2006-01-02T15:04_abc", `parsing time "2006-01-02T15:04_abc" as "2006-01-02T15:04:05Z07:00": cannot parse "_abc" as ":"`},
+       {RFC3339, "2006-01-02T15:04:05_abc", `parsing time "2006-01-02T15:04:05_abc" as "2006-01-02T15:04:05Z07:00": cannot parse "_abc" as "Z07:00"`},
+       {RFC3339, "2006-01-02T15:04:05Z_abc", `parsing time "2006-01-02T15:04:05Z_abc": extra text: _abc`},
 }
 
 func TestParseErrors(t *testing.T) {