Skip to content

Commit

Permalink
fix ulid regex (#2225)
Browse files Browse the repository at this point in the history
  • Loading branch information
r0ots committed Oct 4, 2023
1 parent dfe3719 commit cd7991e
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 2 deletions.
2 changes: 2 additions & 0 deletions deno/lib/__tests__/string.test.ts
Expand Up @@ -266,6 +266,8 @@ test("ulid", () => {
ulid.parse("01ARZ3NDEKTSV4RRFFQ69G5FAV");
const result = ulid.safeParse("invalidulid");
expect(result.success).toEqual(false);
const tooLong = "01ARZ3NDEKTSV4RRFFQ69G5FAVA"
expect(ulid.safeParse(tooLong).success).toEqual(false);
if (!result.success) {
expect(result.error.issues[0].message).toEqual("Invalid ulid");
}
Expand Down
2 changes: 1 addition & 1 deletion deno/lib/types.ts
Expand Up @@ -547,7 +547,7 @@ export interface ZodStringDef extends ZodTypeDef {

const cuidRegex = /^c[^\s-]{8,}$/i;
const cuid2Regex = /^[a-z][a-z0-9]*$/;
const ulidRegex = /[0-9A-HJKMNP-TV-Z]{26}/;
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;
const uuidRegex =
Expand Down
2 changes: 2 additions & 0 deletions src/__tests__/string.test.ts
Expand Up @@ -265,6 +265,8 @@ test("ulid", () => {
ulid.parse("01ARZ3NDEKTSV4RRFFQ69G5FAV");
const result = ulid.safeParse("invalidulid");
expect(result.success).toEqual(false);
const tooLong = "01ARZ3NDEKTSV4RRFFQ69G5FAVA"
expect(ulid.safeParse(tooLong).success).toEqual(false);
if (!result.success) {
expect(result.error.issues[0].message).toEqual("Invalid ulid");
}
Expand Down
2 changes: 1 addition & 1 deletion src/types.ts
Expand Up @@ -547,7 +547,7 @@ export interface ZodStringDef extends ZodTypeDef {

const cuidRegex = /^c[^\s-]{8,}$/i;
const cuid2Regex = /^[a-z][a-z0-9]*$/;
const ulidRegex = /[0-9A-HJKMNP-TV-Z]{26}/;
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;
const uuidRegex =
Expand Down

0 comments on commit cd7991e

Please sign in to comment.