Skip to content

Commit 5d0f88f

Browse files
fix: UUID V4 generation (#138)
1 parent febecdf commit 5d0f88f

File tree

2 files changed

+2
-2
lines changed

2 files changed

+2
-2
lines changed

uuid.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,5 @@ func (UUID) V4() (uuid string) {
1717
io.ReadFull(rand.Reader, uiq[:])
1818
uiq[6] = (uiq[6] & 0x0f) | 0x40 // Version 4
1919
uiq[8] = (uiq[8]&(0xff>>2) | (0x02 << 6)) // Variant RFC4122
20-
return fmt.Sprintf("%x%x%x%x%x", uiq[0:4], uiq[4:6], uiq[6:8], uiq[8:10], uiq[10:])
20+
return fmt.Sprintf("%x-%x-%x-%x-%x", uiq[0:4], uiq[4:6], uiq[6:8], uiq[8:10], uiq[10:])
2121
}

uuid_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import (
88
func TestUUIDv4(t *testing.T) {
99
f := New()
1010
value := f.UUID().V4()
11-
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)
11+
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)
1212
Expect(t, true, err == nil)
1313
Expect(t, true, match)
1414
}

0 commit comments

Comments
 (0)