Skip to main content

Bug Tracker

Side navigation

Ticket #4227: extend_object_with_length.patch
File extend_object_with_length.patch, 1.7 KB (added by JDay, March 20, 2009 07:22AM UTC)

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

Index: jquery/test/unit/core.js
===================================================================
--- jquery/test/unit/core.js	(revision 6287)
+++ jquery/test/unit/core.js	(working copy)
@@ -404,7 +404,7 @@
 });
 
 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" },
@@ -461,6 +461,9 @@
 	jQuery.extend(func, { key: "value" } );
 	equals( func.key, "value", "Verify a function can be extended" );
 
+	var ret = jQuery.extend(true, {},{ foo: { length: 'bar'} });
+	ok( !jQuery.isArray( ret ), "Should not convert an ofject with a length property to an array, for #4227" );
+
 	var defaults = { xnumber1: 5, xnumber2: 7, xstring1: "peter", xstring2: "pan" },
 		defaultsCopy = { xnumber1: 5, xnumber2: 7, xstring1: "peter", xstring2: "pan" },
 		options1 = { xnumber2: 1, xstring2: "x" },
Index: jquery/src/core.js
===================================================================
--- jquery/src/core.js	(revision 6287)
+++ jquery/src/core.js	(working copy)
@@ -235,7 +235,7 @@
 				if ( deep && copy && typeof copy === "object" && !copy.nodeType )
 					target[ name ] = jQuery.extend( deep, 
 						// Never move original objects, clone them
-						src || ( copy.length != null ? [ ] : { } )
+						src || ( jQuery.isArray( copy ) ? [ ] : { } )
 					, copy );
 
 				// Don't bring in undefined values
@@ -442,4 +442,4 @@
 	opera: /opera/.test( userAgent ),
 	msie: /msie/.test( userAgent ) && !/opera/.test( userAgent ),
 	mozilla: /mozilla/.test( userAgent ) && !/(compatible|webkit)/.test( userAgent )
-};
\ No newline at end of file
+};

Download in other formats:

Original Format