diff --git a/CHANGELOG.md b/CHANGELOG.md index b2cbda8..54b383b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,7 @@ ### v3.2.4 * Add support for handling protected value unlocking with `Entry` or `Group` being loaded first from XML +* Initialize fresh UUIDs on unmarshal in case they are missing ### v3.2.3 diff --git a/uuid.go b/uuid.go index e438df4..030b88e 100644 --- a/uuid.go +++ b/uuid.go @@ -44,6 +44,10 @@ func (u *UUID) UnmarshalText(text []byte) error { if err != nil { return err } + if length == 0 { + *u = NewUUID() + return nil + } if length != 16 { return ErrInvalidUUIDLength } diff --git a/uuid_test.go b/uuid_test.go index f64e132..2daa62a 100644 --- a/uuid_test.go +++ b/uuid_test.go @@ -28,4 +28,16 @@ func TestUUID(t *testing.T) { if err != ErrInvalidUUIDLength { t.Fatalf("Expected invalid uuid error, got: %s", err) } + + four := UUID{} + err = four.UnmarshalText([]byte("")) + if err != nil { + t.Fatalf("Expected no error but received: %s", err) + } + + five := UUID{} + + if five.Compare(four) { + t.Fatalf("four and five UUIDs should not be equal but are") + } }