diff --git a/packages/zod/.gitignore b/packages/zod/.gitignore index 225074551..86d865467 100644 --- a/packages/zod/.gitignore +++ b/packages/zod/.gitignore @@ -4,3 +4,4 @@ **/*.d.ts **/*.d.mts **/*.d.cts +**/package.json diff --git a/packages/zod/src/v4/classic/tests/string.test.ts b/packages/zod/src/v4/classic/tests/string.test.ts index 5e32b9256..a223b878c 100644 --- a/packages/zod/src/v4/classic/tests/string.test.ts +++ b/packages/zod/src/v4/classic/tests/string.test.ts @@ -920,6 +920,8 @@ test("CIDR v6 validation", () => { expect(cidrV6.safeParse("not a cidr").success).toBe(false); // Invalid format expect(cidrV6.safeParse("192.168.0.0/24").success).toBe(false); // IPv4 CIDR in v6 validation expect(cidrV6.safeParse("2001:0db8:85a3::/64/whatever-after").success).toBe(false); + expect(cidrV6.safeParse("22d9:f4a8:6a90:f3bf:dcaa:2beb:5fba:0000/112").success).toBe(true); + expect(cidrV6.safeParse("22d9:f4a8:6a90:f3bf:dcaa:2beb:5fba:0000/112/268").success).toBe(false); }); test("E.164 validation", () => { diff --git a/packages/zod/src/v4/core/schemas.ts b/packages/zod/src/v4/core/schemas.ts index b410d79dd..98aa588b1 100644 --- a/packages/zod/src/v4/core/schemas.ts +++ b/packages/zod/src/v4/core/schemas.ts @@ -830,10 +830,11 @@ export const $ZodCIDRv6: core.$constructor<$ZodCIDRv6> = /*@__PURE__*/ core.$con $ZodStringFormat.init(inst, def); inst._zod.check = (payload) => { - const segments = payload.value.split("/"); - const [address, prefix] = segments; + const parts = payload.value.split("/"); try { - if (segments.length !== 2) throw new Error(); + if (parts.length !== 2) throw new Error(); + const [address, prefix] = parts; + if (!prefix) throw new Error(); const prefixNum = Number(prefix); if (`${prefixNum}` !== prefix) throw new Error(); if (prefixNum < 0 || prefixNum > 128) throw new Error(); @@ -1763,7 +1764,7 @@ export interface $ZodObject< function normalizeDef(def: $ZodObjectDef) { const keys = Object.keys(def.shape); for (const k of keys) { - if (!def.shape[k]._zod.traits.has("$ZodType")) { + if (!def.shape?.[k]?._zod?.traits?.has("$ZodType")) { throw new Error(`Invalid element at key "${k}": expected a Zod schema`); } }