From 76397f5ec10eb229830c2ee8ff0d2c003e1f898b Mon Sep 17 00:00:00 2001 From: Artem Berezin Date: Thu, 3 Aug 2017 18:18:45 +1000 Subject: [PATCH] Fix panic on NullTime.UnmarshalJSON ```json type WithDate struct { Time dat.NullTime `json:"time"` } func TestParseNumberAsDate(t *testing.T) { data := `{"time":5}` result := &WithDate{} json.Unmarshal([]byte(data), result) // PANIC! } ``` --- types.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/types.go b/types.go index 0fb9d7e..548d7ec 100644 --- a/types.go +++ b/types.go @@ -182,6 +182,9 @@ func (n *NullTime) UnmarshalJSON(b []byte) error { } s := string(b) + if len(s) < 2 { + return logger.Error("Cannot parse time", "time", s) + } s = s[1 : len(s)-1] for _, format := range formats { t, err := time.Parse(format, s)