aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorOleg Gaidarenko <markelog@gmail.com>2015-12-09 18:41:41 +0300
committerOleg Gaidarenko <markelog@gmail.com>2015-12-09 18:43:05 +0300
commit077bf7341e0ea9276da018613bc8676b91b02bdb (patch)
tree6eb6489f6d3f8d219fb3744343b6da76560de71d
parent4fea389ad2b7515bc3a9081245979ab7be566b99 (diff)
downloadjquery-077bf7341e0ea9276da018613bc8676b91b02bdb.tar.gz
jquery-077bf7341e0ea9276da018613bc8676b91b02bdb.zip
Revert "Core: make isNumeric limited to strings and numbers"
This reverts commit 15ac848868e993dfe5ccd7751a94f5c8edc288bc.
-rw-r--r--src/core.js12
-rw-r--r--test/unit/core.js2
2 files changed, 7 insertions, 7 deletions
diff --git a/src/core.js b/src/core.js
index e8f0d9d37..f27306587 100644
--- a/src/core.js
+++ b/src/core.js
@@ -214,12 +214,12 @@ jQuery.extend( {
isNumeric: function( obj ) {
- // 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;
+ // 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;
},
isPlainObject: function( obj ) {
diff --git a/test/unit/core.js b/test/unit/core.js
index 6aa2a3d63..dc083de31 100644
--- a/test/unit/core.js
+++ b/test/unit/core.js
@@ -455,8 +455,8 @@ QUnit.test( "isNumeric", function( assert ) {
assert.ok( t( 1.5999999999999999 ), "Very precise floating point number" );
assert.ok( t( 8e5 ), "Exponential notation" );
assert.ok( t( "123e-2" ), "Exponential notation string" );
+ assert.ok( t( new ToString( "42" ) ), "Custom .toString returning number" );
- assert.equal( t( new ToString( "42" ) ), false, "Custom .toString returning number" );
assert.equal( t( "" ), false, "Empty string" );
assert.equal( t( " " ), false, "Whitespace characters string" );
assert.equal( t( "\t\t" ), false, "Tab characters string" );