diff --git a/uuid.go b/uuid.go index dc75cee..0b41737 100644 --- a/uuid.go +++ b/uuid.go @@ -224,6 +224,14 @@ func Validate(s string) error { switch len(s) { // Standard UUID format case 36: + if s[8] != '-' || s[13] != '-' || s[18] != '-' || s[23] != '-' { + return ErrInvalidUUIDFormat + } + for _, x := range []int{0, 2, 4, 6, 9, 11, 14, 16, 19, 21, 24, 26, 28, 30, 32, 34} { + if _, ok := xtob(s[x], s[x+1]); !ok { + return ErrInvalidUUIDFormat + } + } // UUID with "urn:uuid:" prefix case 36 + 9: @@ -252,18 +260,6 @@ func Validate(s string) error { return invalidLengthError{len(s)} } - // Check for standard UUID format - if len(s) == 36 { - if s[8] != '-' || s[13] != '-' || s[18] != '-' || s[23] != '-' { - return ErrInvalidUUIDFormat - } - for _, x := range []int{0, 2, 4, 6, 9, 11, 14, 16, 19, 21, 24, 26, 28, 30, 32, 34} { - if _, ok := xtob(s[x], s[x+1]); !ok { - return ErrInvalidUUIDFormat - } - } - } - return nil }