Skip to content

Commit

Permalink
Merge pull request araddon#124 from radaiming/master
Browse files Browse the repository at this point in the history
Fix possible panic
  • Loading branch information
araddon authored Apr 29, 2021
2 parents 0eec95c + 5dd51ed commit 6b43995
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
2 changes: 1 addition & 1 deletion parseany.go
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ func parseTime(datestr string, loc *time.Location, opts ...ParserOption) (p *par
// this is because it means that a day is being interpreted as a month and overflowing the valid value for that
// by retrying in this case, we can fix a common situation with no assumptions
defer func() {
if p.ambiguousMD {
if p != nil && p.ambiguousMD {
// if it errors out with the following error, swap before we
// get out of this function to reduce scope it needs to be applied on
_, err := p.parse()
Expand Down
3 changes: 3 additions & 0 deletions parseany_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -520,6 +520,9 @@ func TestParseErrors(t *testing.T) {
for _, th := range testParseErrors {
v, err := ParseAny(th.in)
assert.NotEqual(t, nil, err, "%v for %v", v, th.in)

v, err = ParseAny(th.in, RetryAmbiguousDateWithSwap(true))
assert.NotEqual(t, nil, err, "%v for %v", v, th.in)
}
}

Expand Down

0 comments on commit 6b43995

Please sign in to comment.