Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix switch-case into Validate func #171

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 8 additions & 12 deletions uuid.go
Original file line number Diff line number Diff line change
Expand Up @@ -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] != '-' {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change would break the 36+2 case.

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:
Expand Down Expand Up @@ -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
}

Expand Down