From 9c18eb2c15a762b4f3137fef9897914c80083a89 Mon Sep 17 00:00:00 2001 From: Anton Ryzhov Date: Wed, 17 Aug 2011 15:30:12 +0400 Subject: $.inArray doesn't crush IE6 and Chrome if second argument is `null` or `undefined` --- src/core.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/core.js b/src/core.js index 7a77ae132..db832a0bf 100644 --- a/src/core.js +++ b/src/core.js @@ -678,6 +678,10 @@ jQuery.extend({ }, inArray: function( elem, array ) { + if (!jQuery.isArray(array)) + { + return -1; + } if ( indexOf ) { return indexOf.call( array, elem ); -- cgit v1.2.3 From 190136cf6132620327a86274fb108fabf55a1d4f Mon Sep 17 00:00:00 2001 From: Anton Ryzhov Date: Wed, 17 Aug 2011 18:56:21 +0400 Subject: Unit test for this case Codestyle fixes --- src/core.js | 3 +-- test/unit/core.js | 10 ++++++++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/core.js b/src/core.js index db832a0bf..eb24a69a4 100644 --- a/src/core.js +++ b/src/core.js @@ -678,8 +678,7 @@ jQuery.extend({ }, inArray: function( elem, array ) { - if (!jQuery.isArray(array)) - { + if ( !array ) { return -1; } diff --git a/test/unit/core.js b/test/unit/core.js index 8c285f6dd..6e245adf7 100644 --- a/test/unit/core.js +++ b/test/unit/core.js @@ -916,6 +916,16 @@ test("jQuery.makeArray", function(){ same( jQuery.makeArray({length: "5"}), [], "Make sure object is coerced properly."); }); +test("jQuery.inArray", function(){ + expect(3); + + equals( jQuery.inArray( 0, false ), -1 , "Search in 'false' as array returns -1 and doesn't throw exception" ); + + equals( jQuery.inArray( 0, null ), -1 , "Search in 'null' as array returns -1 and doesn't throw exception" ); + + equals( jQuery.inArray( 0, undefined ), -1 , "Search in 'undefined' as array returns -1 and doesn't throw exception" ); +}); + test("jQuery.isEmptyObject", function(){ expect(2); -- cgit v1.2.3