colinhacks / zod

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

Lowercase ULIDs should be considered valid ULIDs #3582

Open Qrivi opened 5 months ago

Qrivi commented 5 months ago

Hello everyone.

For a project at work our API uses ULIDs. I noticed Zod comes with a ULID validator built in, however, it always marks our ULIDs as invalid. After a short investigation, I learned that only uppercase ULIDs are considered valid by Zod.

I think the regex Zod uses to check ULID validity, should also allow lowercase ULIDs (or even mix of upper and lower case) as the ULID spec indicates they are case insensitive.

The simple workaround we use right now is z.string().toUpperCase().ulid() (we used to use refine() and a custom validation function), but imo it's not ideal as it affects other validation checks and it might be confusing to other users why lowercase ULIDs are considered invalid. wdyt?

I don't mind working on this myself, as I believe it's just updating the regex to be case insensitive and making sure tests still succeed.

Waziio commented 5 months ago

Hello ! I have modified the ULID regex to make it case insensitive.

Here is the PR