Skip to content

Commit 5dd51ed

Browse files
committed
Fix possible panic
1 parent 0eec95c commit 5dd51ed

File tree

2 files changed

+4
-1
lines changed

2 files changed

+4
-1
lines changed

parseany.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ func parseTime(datestr string, loc *time.Location, opts ...ParserOption) (p *par
240240
// this is because it means that a day is being interpreted as a month and overflowing the valid value for that
241241
// by retrying in this case, we can fix a common situation with no assumptions
242242
defer func() {
243-
if p.ambiguousMD {
243+
if p != nil && p.ambiguousMD {
244244
// if it errors out with the following error, swap before we
245245
// get out of this function to reduce scope it needs to be applied on
246246
_, err := p.parse()

parseany_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -520,6 +520,9 @@ func TestParseErrors(t *testing.T) {
520520
for _, th := range testParseErrors {
521521
v, err := ParseAny(th.in)
522522
assert.NotEqual(t, nil, err, "%v for %v", v, th.in)
523+
524+
v, err = ParseAny(th.in, RetryAmbiguousDateWithSwap(true))
525+
assert.NotEqual(t, nil, err, "%v for %v", v, th.in)
523526
}
524527
}
525528

0 commit comments

Comments
 (0)