Skip to content

Commit

Permalink
fix: UUID V4 generation (#138)
Browse files Browse the repository at this point in the history
  • Loading branch information
pankaj-kumar34 authored May 10, 2023
1 parent febecdf commit 5d0f88f
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion uuid.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@ func (UUID) V4() (uuid string) {
io.ReadFull(rand.Reader, uiq[:])
uiq[6] = (uiq[6] & 0x0f) | 0x40 // Version 4
uiq[8] = (uiq[8]&(0xff>>2) | (0x02 << 6)) // Variant RFC4122
return fmt.Sprintf("%x%x%x%x%x", uiq[0:4], uiq[4:6], uiq[6:8], uiq[8:10], uiq[10:])
return fmt.Sprintf("%x-%x-%x-%x-%x", uiq[0:4], uiq[4:6], uiq[6:8], uiq[8:10], uiq[10:])
}
2 changes: 1 addition & 1 deletion uuid_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
func TestUUIDv4(t *testing.T) {
f := New()
value := f.UUID().V4()
match, err := regexp.MatchString("^[a-fA-F0-9]{8}[a-fA-F0-9]{4}4[a-fA-F0-9]{3}[8|9|aA|bB][a-fA-F0-9]{3}[a-fA-F0-9]{12}$", value)
match, err := regexp.MatchString("^[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-4[a-fA-F0-9]{3}-[8|9|aA|bB][a-fA-F0-9]{3}-[a-fA-F0-9]{12}$", value)
Expect(t, true, err == nil)
Expect(t, true, match)
}
Expand Down

0 comments on commit 5d0f88f

Please sign in to comment.