Skip to content

Commit f9cdc09

Browse files
dsnetgopherbot
authored andcommitted
time: fix Parse for empty seconds
The error return value of the seconds field is overwritten and not checked in the presence of a fractional second. Perform an explicit check for errors. Fixes #54569 Change-Id: I1204c8bdcd5a5a09b773d9e44748141ed1e5cb20 Reviewed-on: https://go-review.googlesource.com/c/go/+/425036 Reviewed-by: Ian Lance Taylor <[email protected]> TryBot-Result: Gopher Robot <[email protected]> Reviewed-by: David Chase <[email protected]> Run-TryBot: Joseph Tsai <[email protected]> Auto-Submit: Joseph Tsai <[email protected]> Reviewed-by: Rob Pike <[email protected]>
1 parent 4e9183c commit f9cdc09

File tree

2 files changed

+5
-0
lines changed

2 files changed

+5
-0
lines changed

src/time/format.go

+3
Original file line numberDiff line numberDiff line change
@@ -1135,6 +1135,9 @@ func parse(layout, value string, defaultLocation, local *Location) (Time, error)
11351135
}
11361136
case stdSecond, stdZeroSecond:
11371137
sec, value, err = getnum(value, std == stdZeroSecond)
1138+
if err != nil {
1139+
break
1140+
}
11381141
if sec < 0 || 60 <= sec {
11391142
rangeErrString = "second"
11401143
break

src/time/format_test.go

+2
Original file line numberDiff line numberDiff line change
@@ -591,6 +591,8 @@ var parseErrorTests = []ParseErrorTest{
591591
{RFC3339, "2006-01-02T15:04:05Z_abc", `parsing time "2006-01-02T15:04:05Z_abc": extra text: "_abc"`},
592592
// invalid second followed by optional fractional seconds
593593
{RFC3339, "2010-02-04T21:00:67.012345678-08:00", "second out of range"},
594+
// issue 54569
595+
{RFC3339, "0000-01-01T00:00:.0+00:00", `parsing time "0000-01-01T00:00:.0+00:00" as "2006-01-02T15:04:05Z07:00": cannot parse ".0+00:00" as "05"`},
594596
// issue 21113
595597
{"_2 Jan 06 15:04 MST", "4 --- 00 00:00 GMT", "cannot parse"},
596598
{"_2 January 06 15:04 MST", "4 --- 00 00:00 GMT", "cannot parse"},

0 commit comments

Comments
 (0)