Bug Tracker

Opened 5 years ago

Closed 5 years ago

Last modified 5 years ago

#10703 closed bug (wontfix)

data() returns zero for long strings starting with '0x'

Reported by: michael.hurley@… Owned by: michael.hurley@…
Priority: low Milestone: None
Component: data Version: 1.7
Keywords: Cc:
Blocked by: Blocking:


trying to retrieve long id strings from the data object is returning zero instead. Since the string begins with '0x' it's not surprising that it's getting interpreted as a number, but it's a bigger number than zero. Retrieving the value of the 'data-umid' attribute behaves properly. Tested in FF7, IE9 & Chrome 15. Proof of concept:

<!doctype html> <html> <head> <script src="http://code.jquery.com/jquery-1.7.min.js"></script> </head> <body> <h1 data-umid="0x060A2B340101010801010D011351000000000000000001F5000000000004F172">Data() test</h1>

<div id="x" style="border:1px solid red"></div>

<script> $(document).ready(function() {


'<p>attr(\'data-umid\') : ' + $('h1').attr('data-umid') + '</p>' + '<p>data().umid: ' + $('h1').data().umid + '</p>'


}); </script>

</body> </html> ~

Change History (7)

comment:1 Changed 5 years ago by timmywil

Component: unfileddata
Owner: set to michael.hurley@…
Priority: undecidedlow
Status: newpending

Thanks for taking the time to contribute to the jQuery project! Please provide a complete reduced test case on jsFiddle to help us assess your ticket.

Additionally, be sure to test against the jQuery Edge version to ensure the issue still exists. To get you started, use this boilerplate: http://jsfiddle.net/FrKyN/ Open the link and click to "Fork" (in the top menu) to get started.

comment:2 Changed 5 years ago by dmethvin

Resolution: invalid
Status: pendingclosed

It's trying to convert that to a number, but it's too big. Use .attr() instead if you just want a string.


comment:3 Changed 5 years ago by michael.hurley@…

How is the number too big?

Number.MAX_VALUE 1.7976931348623157e+308

Number("0x060A2B340101010801010D011351000000000000000001F5000000000004F172") 2.731843739263246e+75

Number.MAX_VALUE > Number("0x060A2B340101010801010D011351000000000000000001F5000000000004F172") true

comment:4 Changed 5 years ago by dmethvin

Resolution: invalid
Status: closedreopened

Yep, I have to agree although I am still not sure why you're converting large hex strings to numbers.

comment:5 Changed 5 years ago by michael.hurley@…

heh. Well, the id comes from the db. I treat it as a string everywhere; I'd love to get the umid back as a string from data(), but data() is trying to coerce it to a number, failing for some unknown reason, and returning zero instead. Using attr() is an acceptable if less than ideal workaround.

comment:6 Changed 5 years ago by dmethvin

Resolution: wontfix
Status: reopenedclosed

As the long article says, if you want a data- attribute as a string with no conversion, don't use .data() because that's not what it is for. You just want the attribute unmolested so .attr() is the right choice. It's not a workaround at all.

That long hex number is returning false from parseFloat so I think we will leave things as-is because this is kind of a pathological case and you really wanted a string anyway.

comment:7 Changed 5 years ago by 0xabad1dea

Well looks like I've found the reason my username fails to parse correctly on half the internet. Good to know I'm a pathological case :'( - 0xabad1dea

Note: See TracTickets for help on using tickets.