Ticket #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: | ||
| Blocking: | Blocked by: |
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
comment:1 Changed 18 months ago by mathias
- Priority changed from undecided to low
- Status changed from new to open
- Type changed from bug to enhancement
Please follow the bug reporting guidlines and use jsFiddle when providing test cases and demonstrations instead of pasting the code in the ticket.
