mirror of
https://github.com/jquery/jquery.git
synced 2026-02-01 05:25:16 -05:00
Core: make isNumeric limited to strings and numbers
Fixes gh-2662
This commit is contained in:
12
src/core.js
12
src/core.js
@@ -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 ) {
|
||||
|
||||
Reference in New Issue
Block a user