diff options
author | Steve Mao <maochenyan@gmail.com> | 2016-01-14 20:22:15 +1100 |
---|---|---|
committer | Richard Gibson <richard.gibson@gmail.com> | 2016-01-24 19:07:09 -0500 |
commit | 7103d8ef47e04a4cf373abee0e8bfa9062fd616f (patch) | |
tree | ef32aefb518017419e53678b95c166cafacb16f7 /src | |
parent | e04e246552c27e872bbf4ae00b55def02b197189 (diff) | |
download | jquery-7103d8ef47e04a4cf373abee0e8bfa9062fd616f.tar.gz jquery-7103d8ef47e04a4cf373abee0e8bfa9062fd616f.zip |
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
Diffstat (limited to 'src')
-rw-r--r-- | src/core.js | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/src/core.js b/src/core.js index 3a54ffc0e..b10128c7a 100644 --- a/src/core.js +++ b/src/core.js @@ -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 ) { |