From 16dfdbe3143bf0a231912b1f8b3d9b808b77fbde Mon Sep 17 00:00:00 2001 From: John-David Dalton Date: Sun, 5 Jan 2014 13:49:18 -0600 Subject: [PATCH] Ensure `shimIsPlainObject` returns true for plain objects with a `constructor` property that has a function value. --- lodash.js | 3 ++- test/test.js | 22 +++++++++++++--------- 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/lodash.js b/lodash.js index cf6dbf3a9..b46b68a0d 100644 --- a/lodash.js +++ b/lodash.js @@ -1948,7 +1948,8 @@ // avoid non Object objects, `arguments` objects, and DOM elements if (!(value && toString.call(value) == objectClass) || - (ctor = value.constructor, isFunction(ctor) && !(ctor instanceof ctor)) || + (!hasOwnProperty.call(value, 'constructor') && + (ctor = value.constructor, isFunction(ctor) && !(ctor instanceof ctor))) || (!support.argsClass && isArguments(value)) || (!support.nodeClass && isNode(value))) { return false; diff --git a/test/test.js b/test/test.js index 4a070830b..2de7f3155 100644 --- a/test/test.js +++ b/test/test.js @@ -4519,20 +4519,20 @@ this.a = 1; } - strictEqual(_.isPlainObject(new Foo(1)), false); - strictEqual(_.isPlainObject([1, 2, 3]), false); + strictEqual(_.isPlainObject({}), true); strictEqual(_.isPlainObject({ 'a': 1 }), true); + strictEqual(_.isPlainObject({ 'constructor': Foo }), true); + strictEqual(_.isPlainObject([1, 2, 3]), false); + strictEqual(_.isPlainObject(new Foo(1)), false); + }); + + test('should return `true` for objects a [[Prototype]] of `null`', 1, function() { if (create) { strictEqual(_.isPlainObject(create(null)), true); } else { skipTest(); } - if (element) { - strictEqual(_.isPlainObject(element), false); - } else { - skipTest(); - } }); test('should return `true` for plain objects with a custom `valueOf` property', 2, function() { @@ -4549,8 +4549,12 @@ } }); - test('should return `true` for empty objects', 1, function() { - strictEqual(_.isPlainObject({}), true); + test('should return `false` for DOM elements', 1, function() { + if (element) { + strictEqual(_.isPlainObject(element), false); + } else { + skipTest(); + } }); test('should return `false` for Object objects without a [[Class]] of "Object"', 3, function() {