aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRichard Gibson <richard.gibson@gmail.com>2016-03-11 10:48:00 -0500
committerTimmy Willison <timmywillisn@gmail.com>2016-03-14 11:45:07 -0400
commit0c1f72667dd74bf00c6c514ebe8b7e92c3e7ad0e (patch)
treefd042bf9fa01746495d2491b1edee4fc6ff6857e
parent0f5f0c981aeedf56fa5b395029cc06b40c3ac2f1 (diff)
downloadjquery-0c1f72667dd74bf00c6c514ebe8b7e92c3e7ad0e.tar.gz
jquery-0c1f72667dd74bf00c6c514ebe8b7e92c3e7ad0e.zip
Core: Restore 1.x isPlainObject constructor checks
- Guard isPlainObject against inherited scalar constructors Fixes gh-2982 Close gh-2985
-rw-r--r--src/core.js4
-rw-r--r--test/unit/core.js11
2 files changed, 13 insertions, 2 deletions
diff --git a/src/core.js b/src/core.js
index 17673dfac..d2c0da0b6 100644
--- a/src/core.js
+++ b/src/core.js
@@ -235,8 +235,10 @@ jQuery.extend( {
return false;
}
+ // Not own constructor property must be Object
if ( obj.constructor &&
- !hasOwn.call( obj.constructor.prototype, "isPrototypeOf" ) ) {
+ !hasOwn.call( obj, "constructor" ) &&
+ !hasOwn.call( obj.constructor.prototype || {}, "isPrototypeOf" ) ) {
return false;
}
diff --git a/test/unit/core.js b/test/unit/core.js
index 2f4831828..7f58f489a 100644
--- a/test/unit/core.js
+++ b/test/unit/core.js
@@ -286,7 +286,8 @@ QUnit.test( "type for `Symbol`", function( assert ) {
});
QUnit.asyncTest( "isPlainObject", function( assert ) {
- assert.expect( 19 );
+
+ assert.expect( 22 );
var pass, iframe, doc, parentObj, childObj, deep,
fn = function() {};
@@ -294,6 +295,10 @@ QUnit.asyncTest( "isPlainObject", function( assert ) {
// The use case that we want to match
assert.ok( jQuery.isPlainObject( {} ), "{}" );
assert.ok( jQuery.isPlainObject( new window.Object() ), "new Object" );
+ assert.ok( jQuery.isPlainObject( { constructor: fn } ),
+ "plain object with constructor property" );
+ assert.ok( jQuery.isPlainObject( { constructor: "foo" } ),
+ "plain object with primitive constructor property" );
parentObj = { foo: "bar" };
childObj = Object.create( parentObj );
@@ -328,6 +333,10 @@ QUnit.asyncTest( "isPlainObject", function( assert ) {
// Again, instantiated objects shouldn't be matched
assert.ok( !jQuery.isPlainObject( new fn() ), "new fn" );
+ // Instantiated objects with primitive constructors shouldn't be matched
+ fn.prototype.constructor = "foo";
+ assert.ok( !jQuery.isPlainObject( new fn() ), "new fn with primitive constructor" );
+
// Deep object
deep = { "foo": { "baz": true }, "foo2": document };
assert.ok( jQuery.isPlainObject( deep ), "Object with objects is still plain" );