uuidrfcrfc4122

Does RFC 4122 support unhyphenated UUIDs?


I understand that UUID contains a set of characters grouped into 5 groups in an 8-4-4-4-12 character pattern as per RFC 4122. Example: 123e4567-e89b-12d3-a456-42661417400

I am using a popular library by Google for Go to parse UUID (https://github.com/google/uuid). This library in particular parses both 123e4567-e89b-12d3-a456-42661417400 and 123e4567e89b12d3a456426614174000 without any error.

I am supposed to parse a potential UUID as per RFC 4122. But I'm not sure if RFC 4122 considers 123e4567e89b12d3a456426614174000 equally valid as 123e4567-e89b-12d3-a456-42661417400. I haven't found any material on the official documentation that has a SAY whether unhyphenated (or dashed) UUIDs are valid.

Please share your toughts, thanks.


Solution

  • The RFC 4122 defines the string representation for UUID in section 3 as:

      The formal definition of the UUID string representation is
      provided by the following ABNF [7]:
    
      UUID                   = time-low "-" time-mid "-"
                               time-high-and-version "-"
                               clock-seq-and-reserved
                               clock-seq-low "-" node
    

    Based on this any UUID without hyphens is not conforming to the standard.

    ... This library in particular parses both 123e4567-e89b-12d3-a456-42661417400 and 123e4567e89b12d3a456426614174000 without any error.

    And it is explicitly documented as being able to parse non-standard representations for UUID. To cite from the documentation:

    func Parse
    func Parse(s string) (UUID, error)
    Parse decodes s into a UUID or returns an error. Both the standard UUID forms of xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx and urn:uuid:xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx are decoded as well as the Microsoft encoding {xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx} and the raw hex encoding: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.