mirror of
https://github.com/jquery/jquery.git
synced 2024-11-23 02:54:22 +00:00
Revert "Core: make isNumeric limited to strings and numbers"
This reverts commit 15ac848868
.
This commit is contained in:
parent
4fea389ad2
commit
077bf7341e
12
src/core.js
12
src/core.js
@ -214,12 +214,12 @@ jQuery.extend( {
|
|||||||
|
|
||||||
isNumeric: function( obj ) {
|
isNumeric: function( obj ) {
|
||||||
|
|
||||||
// As of jQuery 3.0, isNumeric is limited to
|
// parseFloat NaNs numeric-cast false positives (null|true|false|"")
|
||||||
// strings and numbers (primitives or objects)
|
// ...but misinterprets leading-number strings, particularly hex literals ("0x...")
|
||||||
// that can be coerced to finite numbers (gh-2662)
|
// subtraction forces infinities to NaN
|
||||||
var type = jQuery.type( obj );
|
// adding 1 corrects loss of precision from parseFloat (#15100)
|
||||||
return ( type === "number" || type === "string" ) &&
|
var realStringObj = obj && obj.toString();
|
||||||
( obj - parseFloat( obj ) + 1 ) >= 0;
|
return !jQuery.isArray( obj ) && ( realStringObj - parseFloat( realStringObj ) + 1 ) >= 0;
|
||||||
},
|
},
|
||||||
|
|
||||||
isPlainObject: function( obj ) {
|
isPlainObject: function( obj ) {
|
||||||
|
@ -455,8 +455,8 @@ QUnit.test( "isNumeric", function( assert ) {
|
|||||||
assert.ok( t( 1.5999999999999999 ), "Very precise floating point number" );
|
assert.ok( t( 1.5999999999999999 ), "Very precise floating point number" );
|
||||||
assert.ok( t( 8e5 ), "Exponential notation" );
|
assert.ok( t( 8e5 ), "Exponential notation" );
|
||||||
assert.ok( t( "123e-2" ), "Exponential notation string" );
|
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, "Empty string" );
|
||||||
assert.equal( t( " " ), false, "Whitespace characters string" );
|
assert.equal( t( " " ), false, "Whitespace characters string" );
|
||||||
assert.equal( t( "\t\t" ), false, "Tab characters string" );
|
assert.equal( t( "\t\t" ), false, "Tab characters string" );
|
||||||
|
Loading…
Reference in New Issue
Block a user