Bug Tracker

Opened 12 years ago

Closed 12 years ago

Last modified 11 years ago

#10690 closed bug (fixed)


Reported by: shiroiyamii@… Owned by: dmethvin
Priority: blocker Milestone: 1.7.1
Component: core Version: 1.7
Keywords: Cc:
Blocked by: Blocking:


The isNumeric function use does not give the right result in every case. If the "number" is a date object it returns true, but a date is not a number.

the right functio should be

isNumeric: function( obj ) {
return !isNaN(parseFloat(obj)) && isFinite(obj);

Here's a site (not mine) that proves it:

But 'cause it's not my site I copy pasted the site and add the jQuery function
Result: http://img42.imageshack.us/content_round.php?page=done&l=img42/4489/20111106yami000.png

Change History (5)

comment:1 Changed 12 years ago by Rick Waldron

Component: unfiledcore
Owner: set to shiroiyamii@…
Status: newpending

Thanks for taking the time to contribute to the jQuery project! Please provide a complete reduced test case on jsFiddle to help us assess your ticket!

Additionally, be sure to test against the jQuery Edge version to ensure the issue still exists. To get you started, use this boilerplate: http://jsfiddle.net/FrKyN/ Open the link and click to "Fork" (in the top menu) to get started.

comment:2 Changed 12 years ago by shiroiyamii@…

Status: pendingnew

The problem still exist in the jQuery Edge.

Here is a test case that shows only the date problem

and here is a test case that is more detailed

comment:3 Changed 12 years ago by Rick Waldron

On the "more detailed" test, I'm getting all passing tests, is that correct?

comment:4 Changed 12 years ago by dmethvin

Milestone: None1.7.1
Owner: changed from shiroiyamii@… to dmethvin
Priority: undecidedblocker
Status: newassigned

I'd agree that a Date object isn't logically numeric, although +(new Date) does yield a perfectly usable number and that is essentially what is being measured.

The general case where an object has a .toString() still works for both approaches, and I think we *do* want that. As long as the proposed new code doesn't break that I'm okay with it.


comment:5 Changed 12 years ago by Dave Methvin

Resolution: fixed
Status: assignedclosed

Fix #10690. Make sure .isNumeric() can't get a Date.

Also add tests for custom objects with a .toString() method.

Changeset: 795583d2936a48c6f0048e28f74c5fc71e3a60b0

Note: See TracTickets for help on using tickets.