Bug Tracker

Opened 11 years ago

Closed 11 years ago

Last modified 11 years ago

#10856 closed enhancement (duplicate)

jQuery.isNumeric() returns true for 32+bit integers, results in problem with .data() casting

Reported by: oemebamo Owned by:
Priority: low Milestone: None
Component: unfiled Version: 1.7.1
Keywords: Cc:
Blocked by: Blocking:


When reading a data-attribute from an element that contains a numeric string bigger then 32bits, jQuery returns a wrongly casted value.

<div id="test" data-key="138718128824791043"></div>

If you fetch "$('#test').data('key')" for this element it returns "138718128824791040", which is a different number.

The cause is jQuery.isNumeric() returning true for "138718128824791043", and then .data() doing a parseFloat() for numeric attributes, while the specs for parseInt() and parseFloat() specify it's only safe for 32 bit integers/floats (http://es5.github.com/x15.1.html#x15.1.2.2).

Test case: http://jsfiddle.net/oemebamo/ZdNRK/

Maybe jQuery.isNumeric() shouldn't only check if every character is a digit, but also if the length is safe to cast.

Change History (3)

comment:1 Changed 11 years ago by mathias

Priority: undecidedlow
Status: newopen
Type: bugenhancement

comment:2 Changed 11 years ago by dmethvin

Resolution: duplicate
Status: openclosed

This isn't the fault of .isNumeric(), it's quite true that the data can be converted to a number. It is the fault of the conversion that .data() does on data attributes.

comment:3 Changed 11 years ago by dmethvin

Duplicate of #7579.

Note: See TracTickets for help on using tickets.