From c93b174b920aa31b291d40d919d50f9a11fa41d0 Mon Sep 17 00:00:00 2001 From: Dave Methvin Date: Mon, 3 Mar 2014 22:18:50 -0500 Subject: [PATCH] Core: Arrays like [42] should fail .isNumeric() Fixes #14179 (cherry picked from commit 10efa1f5b44046aab6bcc8423322a41923faa290) --- src/core.js | 2 +- test/unit/core.js | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/core.js b/src/core.js index f446ec304..f09d872b2 100644 --- a/src/core.js +++ b/src/core.js @@ -216,7 +216,7 @@ jQuery.extend({ // parseFloat NaNs numeric-cast false positives (null|true|false|"") // ...but misinterprets leading-number strings, particularly hex literals ("0x...") // subtraction forces infinities to NaN - return obj - parseFloat( obj ) >= 0; + return !jQuery.isArray( obj ) && obj - parseFloat( obj ) >= 0; }, isEmptyObject: function( obj ) { diff --git a/test/unit/core.js b/test/unit/core.js index a5b77e54e..02ad0f221 100644 --- a/test/unit/core.js +++ b/test/unit/core.js @@ -462,7 +462,7 @@ test("isFunction", function() { }); test( "isNumeric", function() { - expect( 36 ); + expect( 38 ); var t = jQuery.isNumeric, Traditionalists = /** @constructor */ function(n) { @@ -510,6 +510,8 @@ test( "isNumeric", function() { equal( t(Number.NEGATIVE_INFINITY), false, "Negative Infinity"); equal( t(rong), false, "Custom .toString returning non-number"); 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( new Date() ), false, "Instance of a Date"); equal( t(function(){} ), false, "Instance of a function"); -- 2.39.5