Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #8104. Problem with Objects that have a numerical length property #355

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/core.js
Expand Up @@ -681,13 +681,13 @@ jQuery.extend({
var i = first.length,
j = 0;

if ( typeof second.length === "number" ) {
if ( second instanceof jQuery || jQuery.type( second ) === "array" ) {
for ( var l = second.length; j < l; j++ ) {
first[ i++ ] = second[ j ];
}

} else {
while ( second[j] !== undefined ) {
while ( second[ j ] !== undefined ) {
first[ i++ ] = second[ j++ ];
}
}
Expand Down
5 changes: 4 additions & 1 deletion test/unit/core.js
Expand Up @@ -860,7 +860,7 @@ test("jQuery.each(Object,Function)", function() {
});

test("jQuery.makeArray", function(){
expect(17);
expect(18);

equals( jQuery.makeArray(jQuery("html>*"))[0].nodeName.toUpperCase(), "HEAD", "Pass makeArray a jQuery object" );

Expand Down Expand Up @@ -897,6 +897,9 @@ test("jQuery.makeArray", function(){
// For #5610
same( jQuery.makeArray({length: "0"}), [], "Make sure object is coerced properly.");
same( jQuery.makeArray({length: "5"}), [], "Make sure object is coerced properly.");

// For #8104
same( jQuery.makeArray({ length: 3 }), [], "Make sure object is coerced properly with numeric length value" );
});

test("jQuery.isEmptyObject", function(){
Expand Down