Commit 323b5c9d authored by Brad Fitzpatrick's avatar Brad Fitzpatrick

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: default avatarIan Lance Taylor <iant@golang.org>
parent 409a667f
......@@ -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) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment