mirror of
https://github.com/golang/go
synced 2024-11-27 02:01:23 -07:00
time: make Parse validate day's lower bound in addition to upper bound
Day 0 is as invalid as day 32. Fixes #17874 Change-Id: I52109d12bafd6d957d00c44d540cb88389fff0a7 Reviewed-on: https://go-review.googlesource.com/33429 Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
This commit is contained in:
parent
409a667f35
commit
323b5c9d37
@ -1012,7 +1012,7 @@ func parse(layout, value string, defaultLocation, local *Location) (Time, error)
|
||||
}
|
||||
|
||||
// Validate the day of the month.
|
||||
if day > daysIn(Month(month), year) {
|
||||
if day < 1 || day > daysIn(Month(month), year) {
|
||||
return Time{}, &ParseError{alayout, avalue, "", value, ": day out of range"}
|
||||
}
|
||||
|
||||
|
@ -224,6 +224,7 @@ var dayOutOfRangeTests = []struct {
|
||||
{"Thu Nov 31 21:00:57 2010", false},
|
||||
{"Thu Dec 31 21:00:57 2010", true},
|
||||
{"Thu Dec 32 21:00:57 2010", false},
|
||||
{"Thu Dec 00 21:00:57 2010", false},
|
||||
}
|
||||
|
||||
func TestParseDayOutOfRange(t *testing.T) {
|
||||
|
Loading…
Reference in New Issue
Block a user