From 9e11ebb62a78140a75f29189849f9c02bedbea1f Mon Sep 17 00:00:00 2001 From: John-David Dalton Date: Thu, 3 Mar 2016 22:46:23 -0800 Subject: [PATCH] Ensure `_.isPlainObject` returns `false` for objects with a custom `[[Prototype]]`. [closes #2085] --- lodash.js | 2 +- test/test.js | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/lodash.js b/lodash.js index a89ca30e7..0eae095ec 100644 --- a/lodash.js +++ b/lodash.js @@ -10607,7 +10607,7 @@ if (proto === null) { return true; } - var Ctor = proto.constructor; + var Ctor = hasOwnProperty.call(proto, 'constructor') && proto.constructor; return (typeof Ctor == 'function' && Ctor instanceof Ctor && funcToString.call(Ctor) == objectCtorString); } diff --git a/test/test.js b/test/test.js index 5b1a2e6c0..b4096c13f 100644 --- a/test/test.js +++ b/test/test.js @@ -10856,6 +10856,18 @@ } }); + QUnit.test('should return `false` for objects with a custom `[[Prototype]]`', function(assert) { + assert.expect(1); + + if (create) { + var object = create({ 'a': 1 }); + assert.strictEqual(_.isPlainObject(object), false); + } + else { + skipAssert(assert); + } + }); + QUnit.test('should return `false` for DOM elements', function(assert) { assert.expect(1);