Skip to content

Commit 62bf4e4

Browse files
fix(ZodError): prevent flatten() from crashing on 'toString' key (#5266)
Uses Object.create(null) to create a prototype-less error object, avoiding collisions with built-in Object properties.Issue #5265
1 parent a0abcc0 commit 62bf4e4

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

packages/zod/src/v3/ZodError.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,7 @@ export class ZodError<T = any> extends Error {
296296
flatten(): typeToFlattenedError<T>;
297297
flatten<U>(mapper?: (issue: ZodIssue) => U): typeToFlattenedError<T, U>;
298298
flatten<U = string>(mapper: (issue: ZodIssue) => U = (issue: ZodIssue) => issue.message as any): any {
299-
const fieldErrors: any = {};
299+
const fieldErrors: any = Object.create(null);
300300
const formErrors: U[] = [];
301301
for (const sub of this.issues) {
302302
if (sub.path.length > 0) {

0 commit comments

Comments
 (0)