Skip to main content

Bug Tracker

Side navigation

#10703 closed bug (wontfix)

Opened November 07, 2011 01:58PM UTC

Closed November 07, 2011 03:13PM UTC

Last modified August 12, 2012 01:26AM UTC

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

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

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() {

$('#x').html(

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

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

);

});

</script>

</body>

</html>

~

Attachments (0)
Change History (7)

Changed November 07, 2011 02:03PM UTC by timmywil comment:1

component: unfileddata
owner: → michael.hurley@espn.com
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.

Changed November 07, 2011 02:07PM UTC by dmethvin comment:2

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.

http://www.learningjquery.com/2011/09/using-jquerys-data-apis

Changed November 07, 2011 02:19PM UTC by michael.hurley@espn.com comment:3

How is the number too big?

Number.MAX_VALUE

1.7976931348623157e+308

Number("0x060A2B340101010801010D011351000000000000000001F5000000000004F172")

2.731843739263246e+75

Number.MAX_VALUE > Number("0x060A2B340101010801010D011351000000000000000001F5000000000004F172")

true

Changed November 07, 2011 02:33PM UTC by dmethvin comment:4

resolution: invalid
status: closedreopened

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

Changed November 07, 2011 02:39PM UTC by michael.hurley@espn.com comment:5

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.

Changed November 07, 2011 03:13PM UTC by dmethvin comment:6

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.

Changed August 12, 2012 01:26AM UTC by 0xabad1dea comment:7

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