From 1a49bc007b770b91c2bf0ad777e7a65542366d79 Mon Sep 17 00:00:00 2001 From: Rob X Date: Sun, 9 Oct 2022 20:04:19 +0800 Subject: [PATCH] Returns nilID when id is invalid (#88) --- id.go | 1 + id_test.go | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/id.go b/id.go index 1f536b4..40c8c99 100644 --- a/id.go +++ b/id.go @@ -239,6 +239,7 @@ func (id *ID) UnmarshalText(text []byte) error { } } if !decode(id, text) { + *id = nilID return ErrInvalidID } return nil diff --git a/id_test.go b/id_test.go index c9ca659..6da1e8f 100644 --- a/id_test.go +++ b/id_test.go @@ -131,6 +131,10 @@ func TestFromStringInvalid(t *testing.T) { if err != ErrInvalidID { t.Errorf("FromString(invalid) err=%v, want %v", err, ErrInvalidID) } + id, err := FromString("c6e52g2mrqcjl44hf179") + if id != nilID { + t.Errorf("FromString() =%v, want %v", id, nilID) + } } type jsonType struct {