mirror of
https://github.com/golang/go
synced 2024-11-20 09:04:44 -07:00
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 <iant@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
This commit is contained in:
parent
a323656bb3
commit
32e117d971
@ -289,7 +289,6 @@ var shortDayNames = []string{
|
|||||||
}
|
}
|
||||||
|
|
||||||
var shortMonthNames = []string{
|
var shortMonthNames = []string{
|
||||||
"---",
|
|
||||||
"Jan",
|
"Jan",
|
||||||
"Feb",
|
"Feb",
|
||||||
"Mar",
|
"Mar",
|
||||||
@ -305,7 +304,6 @@ var shortMonthNames = []string{
|
|||||||
}
|
}
|
||||||
|
|
||||||
var longMonthNames = []string{
|
var longMonthNames = []string{
|
||||||
"---",
|
|
||||||
"January",
|
"January",
|
||||||
"February",
|
"February",
|
||||||
"March",
|
"March",
|
||||||
@ -841,8 +839,10 @@ func parse(layout, value string, defaultLocation, local *Location) (Time, error)
|
|||||||
year, err = atoi(p)
|
year, err = atoi(p)
|
||||||
case stdMonth:
|
case stdMonth:
|
||||||
month, value, err = lookup(shortMonthNames, value)
|
month, value, err = lookup(shortMonthNames, value)
|
||||||
|
month++
|
||||||
case stdLongMonth:
|
case stdLongMonth:
|
||||||
month, value, err = lookup(longMonthNames, value)
|
month, value, err = lookup(longMonthNames, value)
|
||||||
|
month++
|
||||||
case stdNumMonth, stdZeroMonth:
|
case stdNumMonth, stdZeroMonth:
|
||||||
month, value, err = getnum(value, std == stdZeroMonth)
|
month, value, err = getnum(value, std == stdZeroMonth)
|
||||||
if month <= 0 || 12 < month {
|
if month <= 0 || 12 < month {
|
||||||
|
@ -465,6 +465,9 @@ var parseErrorTests = []ParseErrorTest{
|
|||||||
{RFC3339, "2006-01-02T15:04:05Z_abc", `parsing time "2006-01-02T15:04:05Z_abc": extra text: _abc`},
|
{RFC3339, "2006-01-02T15:04:05Z_abc", `parsing time "2006-01-02T15:04:05Z_abc": extra text: _abc`},
|
||||||
// invalid second followed by optional fractional seconds
|
// invalid second followed by optional fractional seconds
|
||||||
{RFC3339, "2010-02-04T21:00:67.012345678-08:00", "second out of range"},
|
{RFC3339, "2010-02-04T21:00:67.012345678-08:00", "second out of range"},
|
||||||
|
// issue 21113
|
||||||
|
{"_2 Jan 06 15:04 MST", "4 --- 00 00:00 GMT", "cannot parse"},
|
||||||
|
{"_2 January 06 15:04 MST", "4 --- 00 00:00 GMT", "cannot parse"},
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestParseErrors(t *testing.T) {
|
func TestParseErrors(t *testing.T) {
|
||||||
|
Loading…
Reference in New Issue
Block a user