Skip to content

Commit 33495d5

Browse files
committed
Fix isPlainObject
1 parent 056e3f8 commit 33495d5

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

packages/zod/src/v4/classic/tests/index.test.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -775,3 +775,15 @@ test("z.promise", async () => {
775775
// // @ts-expect-error
776776
// schema.assertOutput<string>();
777777
// });
778+
779+
test("isPlainObject", () => {
780+
expect(z.core.util.isPlainObject({})).toEqual(true);
781+
expect(z.core.util.isPlainObject(Object.create(null))).toEqual(true);
782+
expect(z.core.util.isPlainObject([])).toEqual(false);
783+
expect(z.core.util.isPlainObject(new Date())).toEqual(false);
784+
expect(z.core.util.isPlainObject(null)).toEqual(false);
785+
expect(z.core.util.isPlainObject(undefined)).toEqual(false);
786+
expect(z.core.util.isPlainObject("string")).toEqual(false);
787+
expect(z.core.util.isPlainObject(123)).toEqual(false);
788+
expect(z.core.util.isPlainObject(Symbol())).toEqual(false);
789+
});

packages/zod/src/v4/core/util.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,11 @@ export const allowsEval: { value: boolean } = cached(() => {
333333
});
334334

335335
export function isPlainObject(data: any): data is Record<PropertyKey, unknown> {
336-
return typeof data === "object" && data !== null && Object.getPrototypeOf(data) === Object.prototype;
336+
return (
337+
typeof data === "object" &&
338+
data !== null &&
339+
(Object.getPrototypeOf(data) === Object.prototype || Object.getPrototypeOf(data) === null)
340+
);
337341
}
338342

339343
export function numKeys(data: any): number {

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy