Core: make isNumeric limited to strings and numbers

Fixes gh-2662
This commit is contained in:
Timmy Willison
2015-10-18 15:50:43 -04:00
parent 1144e754a6
commit 15ac848868
2 changed files with 7 additions and 7 deletions

View File

@@ -210,12 +210,12 @@ jQuery.extend( {
isNumeric: function( obj ) {
// parseFloat NaNs numeric-cast false positives (null|true|false|"")
// ...but misinterprets leading-number strings, particularly hex literals ("0x...")
// subtraction forces infinities to NaN
// adding 1 corrects loss of precision from parseFloat (#15100)
var realStringObj = obj && obj.toString();
return !jQuery.isArray( obj ) && ( realStringObj - parseFloat( realStringObj ) + 1 ) >= 0;
// As of jQuery 3.0, isNumeric is limited to
// strings and numbers (primitives or objects)
// that can be coerced to finite numbers (gh-2662)
var type = jQuery.type( obj );
return ( type === "number" || type === "string" ) &&
( obj - parseFloat( obj ) + 1 ) >= 0;
},
isPlainObject: function( obj ) {