#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: |
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.
Change History (3)
comment:1 Changed 11 years ago by
Priority: | undecided → low |
---|---|
Status: | new → open |
Type: | bug → enhancement |
comment:2 Changed 11 years ago by
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.