Skip to content

Commit 6c93ced

Browse files
committed
Fix isPlainObject.
1 parent 0392801 commit 6c93ced

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

src/functions.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -401,7 +401,10 @@ export function isObject(value: unknown): value is Record<string, unknown>
401401
*/
402402
export function isPlainObject(value: unknown): value is Record<string, unknown>
403403
{
404-
return Object.prototype.toString.call(value) === '[object Object]';
404+
if (Object.prototype.toString.call(value) !== '[object Object]') { return false; }
405+
406+
const prototype: any = Object.getPrototypeOf(value);
407+
return prototype === null || prototype === Object.prototype;
405408
}
406409

407410
/**

test/src/functions.test.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -632,10 +632,13 @@ describe('ObjectUtil:', () =>
632632

633633
it('isPlainObject', () =>
634634
{
635+
class Test {}
636+
635637
assert.isFalse(ObjectUtil.isPlainObject(false));
636638
assert.isFalse(ObjectUtil.isPlainObject(null));
637639
assert.isFalse(ObjectUtil.isPlainObject(void 0));
638640
assert.isFalse(ObjectUtil.isPlainObject(new String('test')));
641+
assert.isFalse(ObjectUtil.isPlainObject(new Test()));
639642

640643
assert.isTrue(ObjectUtil.isPlainObject({}));
641644
assert.isTrue(ObjectUtil.isPlainObject(Object.create(null)));

0 commit comments

Comments
 (0)