Bug Tracker

Ticket #4227: extend_object_with_length.patch

File extend_object_with_length.patch, 1.7 KB (added by JDay, 11 years ago)

Fix and testcase. Use jQuery.isArray() istead of checking for a length property.

  • jquery/test/unit/core.js

     
    404404});
    405405
    406406test("jQuery.extend(Object, Object)", function() {
    407         expect(20);
     407        expect(21);
    408408
    409409        var settings = { xnumber1: 5, xnumber2: 7, xstring1: "peter", xstring2: "pan" },
    410410                options = { xnumber2: 1, xstring2: "x", xxx: "newstring" },
     
    461461        jQuery.extend(func, { key: "value" } );
    462462        equals( func.key, "value", "Verify a function can be extended" );
    463463
     464        var ret = jQuery.extend(true, {},{ foo: { length: 'bar'} });
     465        ok( !jQuery.isArray( ret ), "Should not convert an ofject with a length property to an array, for #4227" );
     466
    464467        var defaults = { xnumber1: 5, xnumber2: 7, xstring1: "peter", xstring2: "pan" },
    465468                defaultsCopy = { xnumber1: 5, xnumber2: 7, xstring1: "peter", xstring2: "pan" },
    466469                options1 = { xnumber2: 1, xstring2: "x" },
  • jquery/src/core.js

     
    235235                                if ( deep && copy && typeof copy === "object" && !copy.nodeType )
    236236                                        target[ name ] = jQuery.extend( deep,
    237237                                                // Never move original objects, clone them
    238                                                 src || ( copy.length != null ? [ ] : { } )
     238                                                src || ( jQuery.isArray( copy ) ? [ ] : { } )
    239239                                        , copy );
    240240
    241241                                // Don't bring in undefined values
     
    442442        opera: /opera/.test( userAgent ),
    443443        msie: /msie/.test( userAgent ) && !/opera/.test( userAgent ),
    444444        mozilla: /mozilla/.test( userAgent ) && !/(compatible|webkit)/.test( userAgent )
    445 };
    446  No newline at end of file
     445};