Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Ticket #9375 (new defect)

Opened 9 months ago

Last modified 3 months ago

[PATCH] [TEST] Object.isNumber(NaN) should be false

Reported by: galendw Assigned to: sam
Priority: low Milestone: 2.x
Component: Prototype Version: edge
Severity: minor Keywords: discuss
Cc:

Description

Prototype's Object.isNumber() function doesn't behave properly when NaN is passed to it. Object.isNumber(NaN) will return true. This happens because the isNumber function only checks if the passed object is a type of "number." Since typeof NaN returns "number", the isNumber function will return true.

While the behavior of Object.isNumber is technically correct, I believe that it should return false when passed NaN. When someone checks if their object is a number, they probably also want to make sure that it isn't NaN.

The file I have attached demonstrates the problem and a possible solution.

Attachments

isnumber.html (0.7 kB) - added by galendw on 08/25/07 10:23:04.
Simple demonstration of problem and possible solution. Must include prototype.js.
is_number_not_is_nan.diff (0.8 kB) - added by norbert on 08/28/07 22:53:41.
My first Prototype patch! So proud.

Change History

08/25/07 10:23:04 changed by galendw

  • attachment isnumber.html added.

Simple demonstration of problem and possible solution. Must include prototype.js.

08/28/07 16:42:12 changed by mislav

  • keywords changed from prototype isNumber NaN to discuss.
  • priority changed from normal to low.
  • severity changed from normal to minor.
  • summary changed from Object.isNumber(NaN) Returns True to Object.isNumber(NaN) should be false.

08/28/07 22:53:41 changed by norbert

  • attachment is_number_not_is_nan.diff added.

My first Prototype patch! So proud.

08/28/07 22:56:19 changed by norbert

  • summary changed from Object.isNumber(NaN) should be false to [PATCH] Object.isNumber(NaN) should be false.

Here's a trivial fix, for if this is indeed the intended behaviour.

02/09/08 18:00:07 changed by foca

  • summary changed from [PATCH] Object.isNumber(NaN) should be false to [PATCH] [TEST] Object.isNumber(NaN) should be false.