-2

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.

Adrian
  • 42,911
  • 6
  • 107
  • 99
vignz.pie
  • 173
  • 2
  • 14
  • 2
    Robustness principle from RFC 1122 may apply: [Be liberal in what you accept, and conservative in what you send](https://www.rfc-editor.org/rfc/rfc1122#page-12) – teapot418 May 22 '23 at 14:33
  • 1
    The RFC you linked to states specifically what the formal definition of the UUID string is with the ABNF in section 3. The fact that the Go library accepts non-hyphenated strings is probably a pragmatic choice to be compatible with some existing software. – JimB May 22 '23 at 14:38

2 Answers2

5

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.

Steffen Ullrich
  • 114,247
  • 10
  • 131
  • 172
0

But I'm not sure if RFC 4122 considers 123e4567e89b12d3a456426614174000 equally valid as 123e4567-e89b-12d3-a456-42661417400

A UUID is a 16 byte binary value, not the string representation of the binary value.

The RFC specifies a standard string representation for UUIDs, but that does not make other string representations invalid by the RFC.

If your application requires input in the standard string representation, then the application should check the string before calling Parse.

Community
  • 1
  • 1