Skip to content

Commit

Permalink
Make sure that empty nodelists continue to map properly. Fixes #8993.
Browse files Browse the repository at this point in the history
  • Loading branch information
jeresig committed May 2, 2011
1 parent 86aa764 commit 6c449fd
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -720,7 +720,7 @@ jQuery.extend({
i = 0,
length = elems.length,
// jquery objects are treated as arrays
isArray = elems instanceof jQuery || length !== undefined && typeof length === "number" && ( ( length > 0 && elems[ 0 ] && elems[ length -1 ] ) || jQuery.isArray( elems ) ) ;
isArray = elems instanceof jQuery || length !== undefined && typeof length === "number" && ( ( length > 0 && elems[ 0 ] && elems[ length -1 ] ) || length === 0 || jQuery.isArray( elems ) ) ;

// Go through the array, translating each of the items to their
if ( isArray ) {
Expand Down
8 changes: 7 additions & 1 deletion test/unit/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -653,7 +653,7 @@ test("first()/last()", function() {
});

test("map()", function() {
expect(7);
expect(8);

same(
jQuery("#ap").map(function(){
Expand Down Expand Up @@ -694,6 +694,12 @@ test("map()", function() {
});
equals( mapped.length, scripts.length, "Map an array(-like) to a hash" );

var nonsense = document.getElementsByTagName("asdf");
var mapped = jQuery.map( nonsense, function( v, k ){
return v;
});
equals( mapped.length, nonsense.length, "Map an empty array(-like) to a hash" );

var flat = jQuery.map( Array(4), function( v, k ){
return k % 2 ? k : [k,k,k];//try mixing array and regular returns
});
Expand Down

0 comments on commit 6c449fd

Please sign in to comment.