Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit aa6f0f0

Browse filesBrowse files
authored
More fixes (#5223)
* Fix error message on invalid shape. Fixes #5218 * Ignore package.jsons * Fix CIDRv6 validation false positive. Fixes #5184
1 parent 9f65038 commit aa6f0f0
Copy full SHA for aa6f0f0

File tree

Expand file treeCollapse file tree

3 files changed

+8
-4
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

3 files changed

+8
-4
lines changed
Open diff view settings
Collapse file

‎packages/zod/.gitignore‎

Copy file name to clipboardExpand all lines: packages/zod/.gitignore
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@
44
**/*.d.ts
55
**/*.d.mts
66
**/*.d.cts
7+
**/package.json
Collapse file

‎packages/zod/src/v4/classic/tests/string.test.ts‎

Copy file name to clipboardExpand all lines: packages/zod/src/v4/classic/tests/string.test.ts
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -920,6 +920,8 @@ test("CIDR v6 validation", () => {
920920
expect(cidrV6.safeParse("not a cidr").success).toBe(false); // Invalid format
921921
expect(cidrV6.safeParse("192.168.0.0/24").success).toBe(false); // IPv4 CIDR in v6 validation
922922
expect(cidrV6.safeParse("2001:0db8:85a3::/64/whatever-after").success).toBe(false);
923+
expect(cidrV6.safeParse("22d9:f4a8:6a90:f3bf:dcaa:2beb:5fba:0000/112").success).toBe(true);
924+
expect(cidrV6.safeParse("22d9:f4a8:6a90:f3bf:dcaa:2beb:5fba:0000/112/268").success).toBe(false);
923925
});
924926

925927
test("E.164 validation", () => {
Collapse file

‎packages/zod/src/v4/core/schemas.ts‎

Copy file name to clipboardExpand all lines: packages/zod/src/v4/core/schemas.ts
+5-4Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -830,10 +830,11 @@ export const $ZodCIDRv6: core.$constructor<$ZodCIDRv6> = /*@__PURE__*/ core.$con
830830
$ZodStringFormat.init(inst, def);
831831

832832
inst._zod.check = (payload) => {
833-
const segments = payload.value.split("/");
834-
const [address, prefix] = segments;
833+
const parts = payload.value.split("/");
835834
try {
836-
if (segments.length !== 2) throw new Error();
835+
if (parts.length !== 2) throw new Error();
836+
const [address, prefix] = parts;
837+
if (!prefix) throw new Error();
837838
const prefixNum = Number(prefix);
838839
if (`${prefixNum}` !== prefix) throw new Error();
839840
if (prefixNum < 0 || prefixNum > 128) throw new Error();
@@ -1763,7 +1764,7 @@ export interface $ZodObject<
17631764
function normalizeDef(def: $ZodObjectDef) {
17641765
const keys = Object.keys(def.shape);
17651766
for (const k of keys) {
1766-
if (!def.shape[k]._zod.traits.has("$ZodType")) {
1767+
if (!def.shape?.[k]?._zod?.traits?.has("$ZodType")) {
17671768
throw new Error(`Invalid element at key "${k}": expected a Zod schema`);
17681769
}
17691770
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.