From 907e5f2e4bbe93e1cb5720b9f6e2f829f237e7f0 Mon Sep 17 00:00:00 2001 From: GamerZero Date: Wed, 17 Apr 2024 02:29:36 +0300 Subject: [PATCH] Fix regex in cuid2 validation to be what cuid2 library expects (#2961) --- deno/lib/__tests__/string.test.ts | 1 - src/__tests__/string.test.ts | 1 - src/types.ts | 2 +- 3 files changed, 1 insertion(+), 3 deletions(-) diff --git a/deno/lib/__tests__/string.test.ts b/deno/lib/__tests__/string.test.ts index ac72d42cd..78a4458ef 100644 --- a/deno/lib/__tests__/string.test.ts +++ b/deno/lib/__tests__/string.test.ts @@ -276,7 +276,6 @@ test("cuid2", () => { validStrings.forEach((s) => cuid2.parse(s)); const invalidStrings = [ "", // empty string - "1z4a98xxat96iws9zmbrgj3a", // starts with a number "tz4a98xxat96iws9zMbrgj3a", // include uppercase "tz4a98xxat96iws-zmbrgj3a", // involve symbols ]; diff --git a/src/__tests__/string.test.ts b/src/__tests__/string.test.ts index 915532272..2eae674b1 100644 --- a/src/__tests__/string.test.ts +++ b/src/__tests__/string.test.ts @@ -275,7 +275,6 @@ test("cuid2", () => { validStrings.forEach((s) => cuid2.parse(s)); const invalidStrings = [ "", // empty string - "1z4a98xxat96iws9zmbrgj3a", // starts with a number "tz4a98xxat96iws9zMbrgj3a", // include uppercase "tz4a98xxat96iws-zmbrgj3a", // involve symbols ]; diff --git a/src/types.ts b/src/types.ts index d7f92f479..d0c5bb204 100644 --- a/src/types.ts +++ b/src/types.ts @@ -572,7 +572,7 @@ export interface ZodStringDef extends ZodTypeDef { } const cuidRegex = /^c[^\s-]{8,}$/i; -const cuid2Regex = /^[a-z][a-z0-9]*$/; +const cuid2Regex = /^[0-9a-z]+$/; const ulidRegex = /^[0-9A-HJKMNP-TV-Z]{26}$/; // const uuidRegex = // /^([a-f0-9]{8}-[a-f0-9]{4}-[1-5][a-f0-9]{3}-[a-f0-9]{4}-[a-f0-9]{12}|00000000-0000-0000-0000-000000000000)$/i;