if ( target.constructor == Boolean ) {\r
deep = target;\r
target = arguments[1] || {};\r
+ // skip the boolean and the target\r
+ i = 2;\r
}\r
\r
+ // Handle case when target is a string or something (possible in deep copy)\r
+ if ( typeof target != "object" )\r
+ target = {};\r
+\r
// extend jQuery itself if only one argument is passed\r
if ( length == 1 ) {\r
target = this;\r
// Extend the base object\r
for ( var name in options ) {\r
// Prevent never-ending loop\r
- if ( target == options[ name ] )\r
+ if ( target === options[ name ] )\r
continue;\r
\r
// Recurse if we're merging object values\r
if ( deep && typeof options[ name ] == "object" && target[ name ] && !options[ name ].nodeType )\r
- jQuery.extend( target[ name ], options[ name ] );\r
+ target[ name ] = jQuery.extend( target[ name ], options[ name ] );\r
\r
// Don't bring in undefined values\r
else if ( options[ name ] != undefined )\r
});
test("$.extend(Object, Object)", function() {
- expect(11);
+ expect(14);
var settings = { xnumber1: 5, xnumber2: 7, xstring1: "peter", xstring2: "pan" },
options = { xnumber2: 1, xstring2: "x", xxx: "newstring" },
isObj( deep2.foo, deep2copy.foo, "Check if not deep2: options must not be modified" );
equals( deep1.foo2, document, "Make sure that a deep clone was not attempted on the document" );
+ var target = {};
+ var recursive = { foo:target, bar:5 };
+ jQuery.extend(true, target, recursive);
+ isObj( target, { bar:5 }, "Check to make sure a recursive obj doesn't go never-ending loop by not copying it over" );
+
+ var ret = jQuery.extend(true, { foo: [] }, { foo: [0] } ); // 1907
+ ok( ret.foo.length == 1, "Check to make sure a value with coersion 'false' copies over when necessary to fix #1907" );
+
+ var ret = jQuery.extend(true, { foo: "1,2,3" }, { foo: [1, 2, 3] } );
+ ok( typeof ret.foo != "string", "Check to make sure values equal with coersion (but not actually equal) overwrite correctly" );
+
var defaults = { xnumber1: 5, xnumber2: 7, xstring1: "peter", xstring2: "pan" },
defaultsCopy = { xnumber1: 5, xnumber2: 7, xstring1: "peter", xstring2: "pan" },
options1 = { xnumber2: 1, xstring2: "x" },