Skip to content

Commit

Permalink
Initialize fresh UUID in case none was provided for some reason
Browse files Browse the repository at this point in the history
  • Loading branch information
tobischo committed Nov 7, 2021
1 parent c9b352e commit 282d7a8
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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

Expand Down
4 changes: 4 additions & 0 deletions uuid.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
12 changes: 12 additions & 0 deletions uuid_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
}

0 comments on commit 282d7a8

Please sign in to comment.