Skip to content

Commit 10efa1f

Browse files
committed
Core: Arrays like [42] should fail .isNumeric()
Fixes #14179
1 parent 279913c commit 10efa1f

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

src/core.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ jQuery.extend({
216216
// parseFloat NaNs numeric-cast false positives (null|true|false|"")
217217
// ...but misinterprets leading-number strings, particularly hex literals ("0x...")
218218
// subtraction forces infinities to NaN
219-
return obj - parseFloat( obj ) >= 0;
219+
return !jQuery.isArray( obj ) && obj - parseFloat( obj ) >= 0;
220220
},
221221

222222
isPlainObject: function( obj ) {

test/unit/core.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -457,7 +457,7 @@ test("isFunction", function() {
457457
});
458458

459459
test( "isNumeric", function() {
460-
expect( 36 );
460+
expect( 38 );
461461

462462
var t = jQuery.isNumeric,
463463
Traditionalists = /** @constructor */ function(n) {
@@ -505,6 +505,8 @@ test( "isNumeric", function() {
505505
equal( t(Number.NEGATIVE_INFINITY), false, "Negative Infinity");
506506
equal( t(rong), false, "Custom .toString returning non-number");
507507
equal( t({}), false, "Empty object");
508+
equal( t( [] ), false, "Empty array" );
509+
equal( t( [ 42 ] ), false, "Array with one number" );
508510
equal( t(function(){} ), false, "Instance of a function");
509511
equal( t( new Date() ), false, "Instance of a Date");
510512
equal( t(function(){} ), false, "Instance of a function");

0 commit comments

Comments
 (0)