Skip to content

Commit 0703fd5

Browse files
LizaLemonsmarkelog
authored andcommitted
Core: make isNumeric test work on Symbol
Ref #2645 Closes #2657
1 parent 44f8239 commit 0703fd5

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

src/core.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,8 @@ jQuery.extend( {
214214
// ...but misinterprets leading-number strings, particularly hex literals ("0x...")
215215
// subtraction forces infinities to NaN
216216
// adding 1 corrects loss of precision from parseFloat (#15100)
217-
return !jQuery.isArray( obj ) && ( obj - parseFloat( obj ) + 1 ) >= 0;
217+
var realStringObj = obj && obj.toString();
218+
return !jQuery.isArray( obj ) && ( realStringObj - parseFloat( realStringObj ) + 1 ) >= 0;
218219
},
219220

220221
isPlainObject: function( obj ) {

test/unit/core.js

+7
Original file line numberDiff line numberDiff line change
@@ -490,6 +490,13 @@ QUnit.test( "isNumeric", function( assert ) {
490490
assert.equal( t( new Date() ), false, "Instance of a Date" );
491491
} );
492492

493+
QUnit[ typeof Symbol === "function" ? "test" : "skip" ]( "isNumeric(Symbol)", function( assert ) {
494+
assert.expect( 2 );
495+
496+
assert.equal( jQuery.isNumeric( Symbol() ), false, "Symbol" );
497+
assert.equal( jQuery.isNumeric( Object( Symbol() ) ), false, "Symbol inside an object" );
498+
} );
499+
493500
QUnit.test( "isXMLDoc - HTML", function( assert ) {
494501
assert.expect( 4 );
495502

0 commit comments

Comments
 (0)