Bug Tracker

Opened 7 years ago

Closed 7 years ago

Last modified 7 years ago

#9917 closed bug (duplicate)

$.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:

Description

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]

Change History (6)

comment:1 Changed 7 years ago by addyosmani

Component: unfileddata
Owner: set to 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: http://jsfiddle.net/FrKyN/

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

comment:2 Changed 7 years ago by addyosmani

#9918 is a duplicate of this ticket.

comment:3 Changed 7 years ago by Rick Waldron

Resolution: duplicate
Status: pendingclosed

comment:4 Changed 7 years ago by Rick Waldron

Duplicate of #9779.

comment:5 Changed 7 years ago by Rick Waldron

Priority: lowblocker

comment:6 Changed 7 years ago by Rick Waldron

#10016 is a duplicate of this ticket.

Note: See TracTickets for help on using tickets.