Skip to content

Commit cfc3145

Browse files
zhe-hetimdorr
andauthored
fix(isPlainObject): support check Object.create(null) (#4633)
Co-authored-by: Tim Dorr <[email protected]>
1 parent 0e8a7b0 commit cfc3145

File tree

2 files changed

+2
-1
lines changed

2 files changed

+2
-1
lines changed

src/utils/isPlainObject.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,5 @@ export default function isPlainObject(obj: any): obj is object {
1010
proto = Object.getPrototypeOf(proto)
1111
}
1212

13-
return Object.getPrototypeOf(obj) === proto
13+
return Object.getPrototypeOf(obj) === proto || Object.getPrototypeOf(obj) === null
1414
}

test/utils/isPlainObject.spec.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,6 @@ describe('isPlainObject', () => {
1212
expect(isPlainObject(null)).toBe(false)
1313
expect(isPlainObject(undefined)).toBe(false)
1414
expect(isPlainObject({ x: 1, y: 2 })).toBe(true)
15+
expect(isPlainObject(Object.create(null))).toBe(true)
1516
})
1617
})

0 commit comments

Comments
 (0)