Core: Improve isNumeric logic and test coverage

Also add back accidentally deleted comments about the implementation.

Fixes gh-2780
Ref gh-2663
Ref gh-2781
Closes gh-2827
This commit is contained in:
Steve Mao
2016-01-14 20:22:15 +11:00
committed by Richard Gibson
parent e04e246552
commit 7103d8ef47
2 changed files with 28 additions and 3 deletions

View File

@@ -217,7 +217,11 @@ jQuery.extend( {
// that can be coerced to finite numbers (gh-2662)
var type = jQuery.type( obj );
return ( type === "number" || type === "string" ) &&
( obj - parseFloat( obj ) + 1 ) >= 0;
// parseFloat NaNs numeric-cast false positives ("")
// ...but misinterprets leading-number strings, particularly hex literals ("0x...")
// subtraction forces infinities to NaN
!isNaN( obj - parseFloat( obj ) );
},
isPlainObject: function( obj ) {