Skip to content

Commit a839af0

Browse files
committed
Merge pull request jquery#465 from anton-ryzhov/master
Fixes #10076. $.inArray crashes IE6 and Chrome if second argument is `null` or `undefined` (Thanks anton-ryzhov!)
2 parents f4811bf + 190136c commit a839af0

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

src/core.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -679,6 +679,9 @@ jQuery.extend({
679679
},
680680

681681
inArray: function( elem, array ) {
682+
if ( !array ) {
683+
return -1;
684+
}
682685

683686
if ( indexOf ) {
684687
return indexOf.call( array, elem );

test/unit/core.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -934,6 +934,16 @@ test("jQuery.makeArray", function(){
934934
same( jQuery.makeArray({length: "5"}), [], "Make sure object is coerced properly.");
935935
});
936936

937+
test("jQuery.inArray", function(){
938+
expect(3);
939+
940+
equals( jQuery.inArray( 0, false ), -1 , "Search in 'false' as array returns -1 and doesn't throw exception" );
941+
942+
equals( jQuery.inArray( 0, null ), -1 , "Search in 'null' as array returns -1 and doesn't throw exception" );
943+
944+
equals( jQuery.inArray( 0, undefined ), -1 , "Search in 'undefined' as array returns -1 and doesn't throw exception" );
945+
});
946+
937947
test("jQuery.isEmptyObject", function(){
938948
expect(2);
939949

0 commit comments

Comments
 (0)