From c6bc80de5091c634a371cc81877df816a269e965 Mon Sep 17 00:00:00 2001 From: Mohamed Azdoud <103521660+Waziio@users.noreply.github.com> Date: Sat, 29 Jun 2024 02:50:29 +0200 Subject: [PATCH] Fix issue #3582 : ULID should be case insensitive (#3593) * Fix issue #3582 : ULID should be case insensitive * Use i flag --------- Co-authored-by: AZDOUD Mohamed Co-authored-by: Colin McDonnell --- deno/lib/__tests__/string.test.ts | 2 ++ deno/lib/types.ts | 2 +- src/__tests__/string.test.ts | 2 ++ src/types.ts | 2 +- 4 files changed, 6 insertions(+), 2 deletions(-) diff --git a/deno/lib/__tests__/string.test.ts b/deno/lib/__tests__/string.test.ts index 3f5b95562..3fc6ec0f4 100644 --- a/deno/lib/__tests__/string.test.ts +++ b/deno/lib/__tests__/string.test.ts @@ -331,6 +331,8 @@ test("ulid", () => { if (!result.success) { expect(result.error.issues[0].message).toEqual("Invalid ulid"); } + const caseInsensitive = ulid.safeParse("01arZ3nDeKTsV4RRffQ69G5FAV") + expect(caseInsensitive.success).toEqual(true) }); test("regex", () => { diff --git a/deno/lib/types.ts b/deno/lib/types.ts index 9a6311289..d634e524f 100644 --- a/deno/lib/types.ts +++ b/deno/lib/types.ts @@ -575,7 +575,7 @@ export interface ZodStringDef extends ZodTypeDef { const cuidRegex = /^c[^\s-]{8,}$/i; const cuid2Regex = /^[0-9a-z]+$/; -const ulidRegex = /^[0-9A-HJKMNP-TV-Z]{26}$/; +const ulidRegex = /^[0-9A-HJKMNP-TV-Z]{26}$/i; // 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; const uuidRegex = diff --git a/src/__tests__/string.test.ts b/src/__tests__/string.test.ts index db01a64eb..b79664fff 100644 --- a/src/__tests__/string.test.ts +++ b/src/__tests__/string.test.ts @@ -330,6 +330,8 @@ test("ulid", () => { if (!result.success) { expect(result.error.issues[0].message).toEqual("Invalid ulid"); } + const caseInsensitive = ulid.safeParse("01arZ3nDeKTsV4RRffQ69G5FAV") + expect(caseInsensitive.success).toEqual(true) }); test("regex", () => { diff --git a/src/types.ts b/src/types.ts index f89acb5e0..0767073c5 100644 --- a/src/types.ts +++ b/src/types.ts @@ -575,7 +575,7 @@ export interface ZodStringDef extends ZodTypeDef { const cuidRegex = /^c[^\s-]{8,}$/i; const cuid2Regex = /^[0-9a-z]+$/; -const ulidRegex = /^[0-9A-HJKMNP-TV-Z]{26}$/; +const ulidRegex = /^[0-9A-HJKMNP-TV-Z]{26}$/i; // 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; const uuidRegex =