Skip to main content

Bug Tracker

Side navigation

#9917 closed bug (duplicate)

Opened July 27, 2011 09:28AM UTC

Closed July 27, 2011 02:32PM UTC

Last modified August 10, 2011 08:14PM UTC

$.data returns undefined for any stored false value

Reported by: anonymous Owned by: anonymous
Priority: blocker Milestone: None
Component: data Version: 1.6.2
Keywords: Cc:
Blocked by: Blocking:

If you store 0, false or null as a value for the data, it will always return undefined. Reason being, if it is stored as a camelized key, the below condition will always fail, and then $.data will always return the nonexisting non-camelized data, which is undefined.

The offending code is this, at the end of the $.data function:

 thisCache[ jQuery.camelCase( name ) ] || thisCache[ name ] 

This problem is especially bad, if 0 is stored as the data, and during retrieval, it is expected to be of a numeric type. With undefined, any numerical expression will result in NaN.

The above code should be changed to :

var camelName = jQuery.camelCase(name);
camelName in thisCache
 ? thisCache[camelName] : thisCache[name]
Attachments (0)
Change History (6)

Changed July 27, 2011 11:38AM UTC by addyosmani comment:1

component: unfileddata
owner: → anonymous
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:

Open the link and click to "Fork" (in the top menu) to get started.

Changed July 27, 2011 11:40AM UTC by addyosmani comment:2

#9918 is a duplicate of this ticket.

Changed July 27, 2011 02:32PM UTC by rwaldron comment:3

resolution: → duplicate
status: pendingclosed

Changed July 27, 2011 02:33PM UTC by rwaldron comment:4

Duplicate of #9779.

Changed August 10, 2011 08:14PM UTC by rwaldron comment:5

priority: lowblocker

Changed August 10, 2011 08:14PM UTC by rwaldron comment:6

#10016 is a duplicate of this ticket.