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

uuid.Parse allows invalid UUID's #131

Closed
dhuckins opened this issue Sep 28, 2023 · 2 comments
Closed

uuid.Parse allows invalid UUID's #131

dhuckins opened this issue Sep 28, 2023 · 2 comments

Comments

@dhuckins
Copy link

it seems that there are some cases where uuid.Parse is not throwing an error for invalid uuids
examples of invalid UUID's that do not give errors

  • extra dashes: -6ba7b810-9dad-11d1-80b4-00c04fd430c8-
  • extra characters: 06ba7b810-9dad-11d1-80b4-00c04fd430c81
  • quotes: "6ba7b810-9dad-11d1-80b4-00c04fd430c8"

see here for a reproducible example

@bormanp
Copy link
Collaborator

bormanp commented Oct 3, 2023

This is a known "feature" and has been discussed before. Fixing this could very well break existing code. I actually don't see any issue with the first and third examples. The current code also can parse [6ba7b810-9dad-11d1-80b4-00c04fd430c8], <6ba7b810-9dad-11d1-80b4-00c04fd430c8>, (6ba7b810-9dad-11d1-80b4-00c04fd430c8), '6ba7b810-9dad-11d1-80b4-00c04fd430c8' all of which I have no particular problem with. I agree that the seocnd example does not return an error is unfortunate. In any event, the time for this change has long since passed.

If validating, rather than just parsing, strings as UUIDs I could imagine a function like:

func Validate(s string) (uuid, error) {
    if len(s) == 36 + 2 { 
      // do some checks
    }
    return Parse(s)
}

@bormanp
Copy link
Collaborator

bormanp commented Oct 3, 2023

This is a duplicate of issue #60

@bormanp bormanp closed this as completed Oct 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants