Core: Arrays like [42] should fail .isNumeric()

Fixes #14179
(cherry picked from commit 10efa1f5b4)
This commit is contained in:
Dave Methvin 2014-03-03 22:18:50 -05:00
parent a9fa2ec763
commit c93b174b92
2 changed files with 4 additions and 2 deletions

View File

@ -216,7 +216,7 @@ jQuery.extend({
// parseFloat NaNs numeric-cast false positives (null|true|false|"") // parseFloat NaNs numeric-cast false positives (null|true|false|"")
// ...but misinterprets leading-number strings, particularly hex literals ("0x...") // ...but misinterprets leading-number strings, particularly hex literals ("0x...")
// subtraction forces infinities to NaN // subtraction forces infinities to NaN
return obj - parseFloat( obj ) >= 0; return !jQuery.isArray( obj ) && obj - parseFloat( obj ) >= 0;
}, },
isEmptyObject: function( obj ) { isEmptyObject: function( obj ) {

View File

@ -462,7 +462,7 @@ test("isFunction", function() {
}); });
test( "isNumeric", function() { test( "isNumeric", function() {
expect( 36 ); expect( 38 );
var t = jQuery.isNumeric, var t = jQuery.isNumeric,
Traditionalists = /** @constructor */ function(n) { Traditionalists = /** @constructor */ function(n) {
@ -510,6 +510,8 @@ test( "isNumeric", function() {
equal( t(Number.NEGATIVE_INFINITY), false, "Negative Infinity"); equal( t(Number.NEGATIVE_INFINITY), false, "Negative Infinity");
equal( t(rong), false, "Custom .toString returning non-number"); equal( t(rong), false, "Custom .toString returning non-number");
equal( t({}), false, "Empty object"); equal( t({}), false, "Empty object");
equal( t( [] ), false, "Empty array" );
equal( t( [ 42 ] ), false, "Array with one number" );
equal( t(function(){} ), false, "Instance of a function"); equal( t(function(){} ), false, "Instance of a function");
equal( t( new Date() ), false, "Instance of a Date"); equal( t( new Date() ), false, "Instance of a Date");
equal( t(function(){} ), false, "Instance of a function"); equal( t(function(){} ), false, "Instance of a function");