Skip to content

Commit 32e117d

Browse files
choleraehyqianlancetaylor
authored andcommitted
time: don't match '---' month in time.Parse
The existing implementation will panic when month in date string is '---'. Fixed #21113 Change-Id: I8058ae7a4102e882f8b7e9c65d80936b563265e4 Reviewed-on: https://go-review.googlesource.com/51010 Run-TryBot: Ian Lance Taylor <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> Reviewed-by: Ian Lance Taylor <[email protected]>
1 parent a323656 commit 32e117d

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

src/time/format.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,6 @@ var shortDayNames = []string{
289289
}
290290

291291
var shortMonthNames = []string{
292-
"---",
293292
"Jan",
294293
"Feb",
295294
"Mar",
@@ -305,7 +304,6 @@ var shortMonthNames = []string{
305304
}
306305

307306
var longMonthNames = []string{
308-
"---",
309307
"January",
310308
"February",
311309
"March",
@@ -841,8 +839,10 @@ func parse(layout, value string, defaultLocation, local *Location) (Time, error)
841839
year, err = atoi(p)
842840
case stdMonth:
843841
month, value, err = lookup(shortMonthNames, value)
842+
month++
844843
case stdLongMonth:
845844
month, value, err = lookup(longMonthNames, value)
845+
month++
846846
case stdNumMonth, stdZeroMonth:
847847
month, value, err = getnum(value, std == stdZeroMonth)
848848
if month <= 0 || 12 < month {

src/time/format_test.go

+3
Original file line numberDiff line numberDiff line change
@@ -465,6 +465,9 @@ var parseErrorTests = []ParseErrorTest{
465465
{RFC3339, "2006-01-02T15:04:05Z_abc", `parsing time "2006-01-02T15:04:05Z_abc": extra text: _abc`},
466466
// invalid second followed by optional fractional seconds
467467
{RFC3339, "2010-02-04T21:00:67.012345678-08:00", "second out of range"},
468+
// issue 21113
469+
{"_2 Jan 06 15:04 MST", "4 --- 00 00:00 GMT", "cannot parse"},
470+
{"_2 January 06 15:04 MST", "4 --- 00 00:00 GMT", "cannot parse"},
468471
}
469472

470473
func TestParseErrors(t *testing.T) {

0 commit comments

Comments
 (0)