Side navigation
#10856 closed enhancement (duplicate)
Opened November 22, 2011 12:03PM UTC
Closed November 22, 2011 01:51PM UTC
Last modified March 14, 2012 11:00AM UTC
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: |
Description
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.
Attachments (0)
Change History (3)
Changed November 22, 2011 12:26PM UTC by comment:1
priority: | undecided → low |
---|---|
status: | new → open |
type: | bug → enhancement |
Changed November 22, 2011 01:51PM UTC by comment:2
resolution: | → duplicate |
---|---|
status: | open → closed |
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.