From 7103d8ef47e04a4cf373abee0e8bfa9062fd616f Mon Sep 17 00:00:00 2001 From: Steve Mao Date: Thu, 14 Jan 2016 20:22:15 +1100 Subject: 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 --- src/core.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'src') 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 ) { -- cgit v1.2.3