Skip to content

Commit d846c25

Browse files
LizaLemonsgibson042
authored andcommitted
Core: make isNumeric test work on Symbol
Ref #2645 Closes #2657 (cherry picked from commit 0703fd5)
1 parent 20cd343 commit d846c25

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

src/core.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,8 @@ jQuery.extend( {
221221
// ...but misinterprets leading-number strings, particularly hex literals ("0x...")
222222
// subtraction forces infinities to NaN
223223
// adding 1 corrects loss of precision from parseFloat (#15100)
224-
return !jQuery.isArray( obj ) && ( obj - parseFloat( obj ) + 1 ) >= 0;
224+
var realStringObj = obj && obj.toString();
225+
return !jQuery.isArray( obj ) && ( realStringObj - parseFloat( realStringObj ) + 1 ) >= 0;
225226
},
226227

227228
isEmptyObject: function( obj ) {

test/unit/core.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -504,6 +504,13 @@ QUnit.test( "isNumeric", function( assert ) {
504504
assert.equal( t( new Date() ), false, "Instance of a Date" );
505505
} );
506506

507+
QUnit[ typeof Symbol === "function" ? "test" : "skip" ]( "isNumeric(Symbol)", function( assert ) {
508+
assert.expect( 2 );
509+
510+
assert.equal( jQuery.isNumeric( Symbol() ), false, "Symbol" );
511+
assert.equal( jQuery.isNumeric( Object( Symbol() ) ), false, "Symbol inside an object" );
512+
} );
513+
507514
QUnit.test( "isXMLDoc - HTML", function( assert ) {
508515
assert.expect( 4 );
509516

0 commit comments

Comments
 (0)