jQuery.extend(true, Object, Object) copies objects with length keys correctly
authorYehuda Katz <wycats@gmail.com>
Thu, 16 Jul 2009 07:31:55 +0000 (07:31 +0000)
committerYehuda Katz <wycats@gmail.com>
Thu, 16 Jul 2009 07:31:55 +0000 (07:31 +0000)
src/core.js
test/unit/core.js

index 1721bda..6f8d40f 100644 (file)
@@ -245,7 +245,7 @@ jQuery.extend = jQuery.fn.extend = function() {
                                if ( deep && copy && typeof copy === "object" && !copy.nodeType ) {
                                        target[ name ] = jQuery.extend( deep,
                                                // Never move original objects, clone them
-                                               src || ( copy.length != null ? [ ] : { } ), copy );
+                                               src || ( jQuery.isArray(copy) ? [ ] : { } ), copy );
 
                                // Don't bring in undefined values
                                } else if ( copy !== undefined ) {
index 347864e..fe2e992 100644 (file)
@@ -435,7 +435,7 @@ test("jQuery.merge()", function() {
 });
 
 test("jQuery.extend(Object, Object)", function() {
-       expect(20);
+       expect(21);
 
        var settings = { xnumber1: 5, xnumber2: 7, xstring1: "peter", xstring2: "pan" },
                options = { xnumber2: 1, xstring2: "x", xxx: "newstring" },
@@ -460,6 +460,12 @@ test("jQuery.extend(Object, Object)", function() {
        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 empty = {};
+       var optionsWithLength = { foo: { length: -1 } };
+       jQuery.extend(true, empty, optionsWithLength);
+
+       isObj( empty.foo, optionsWithLength.foo, "The length property must copy correctly" );
+
        var nullUndef;
        nullUndef = jQuery.extend({}, options, { xnumber2: null });
        ok( nullUndef.xnumber2 === null, "Check to make sure null values are copied");