colinhacks / zod

TypeScript-first schema validation with static type inference
https://zod.dev
MIT License
33.96k stars 1.19k forks source link

Support for curly braces around UUID/GUID #3606

Open James3UK opened 4 months ago

James3UK commented 4 months ago

Curly braces around UUID's are very common in Microsoft applications also interchangeably referred to as GUIDs it would be great if these could also be validated, maybe a separate GUID validator or some options?

As far as I can see the PR by @jeansibelius merged in v4 for GUIDs also does not cater for the curly braces https://github.com/colinhacks/zod/pull/2872

PostgreSQL also accepts the following alternative forms for input: use of upper-case digits, the standard format surrounded by braces, omitting some or all hyphens, adding a hyphen after any group of four digits. Examples are:

A0EEBC99-9C0B-4EF8-BB6D-6BB9BD380A11 {a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a11} a0eebc999c0b4ef8bb6d6bb9bd380a11 a0ee-bc99-9c0b-4ef8-bb6d-6bb9-bd38-0a11 {a0eebc99-9c0b4ef8-bb6d6bb9-bd380a11}

https://www.postgresql.org/docs/current/datatype-uuid.html

Microsoft refer to this here https://learn.microsoft.com/en-us/openspecs/windows_protocols/ms-dtyp/a66edeb1-52a0-

4d64-a93b-2f5c833d7d92#gt_b753d3f3-f3b7-4fee-bf4d-63085e108ec9): curly braced GUID string: The string representation of a 128-bit globally unique identifier (GUID) using the form {XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX}, where X denotes a hexadecimal digit. The string representation between the enclosing braces is the standard representation of a GUID as described in [RFC4122] section 3. Unlike a GUIDString, a curly braced GUID string includes enclosing braces.

and here https://learn.microsoft.com/en-us/openspecs/windows_protocols/ms-dtyp/222af2d3-5c00-4899-bc87-ed4c6515e80d

2.3.4.3 GUID--Curly Braced String Representation

The curly braced GUID string representation is a format commonly used for a string representation of the GUID type (as specified in section 2.3.4.1) is described by the following ABNF syntax, as specified in [RFC5234].

CurlyBraceGuidString = "{" UUID "}" Where UUID represents the string form of a UUID, as specified in [RFC4122] section 3. The non-terminal symbol CurlyBraceGuidString represents (that is, generates) strings that satisfy the definition of curly braced GUID string.

By way of illustration, the UUID string specified in [RFC4122] section 3 as an example would have the following representation as a curly braced GUID string.

{f81d4fae-7dec-11d0-a765-00a0c91e6bf6}