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: |
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]
Attachments (0)
Change History (6)
Changed July 27, 2011 11:38AM UTC by comment:1
component: | unfiled → data |
---|---|
owner: | → anonymous |
priority: | undecided → low |
status: | new → pending |
Changed July 27, 2011 02:32PM UTC by comment:3
resolution: | → duplicate |
---|---|
status: | pending → closed |
Changed August 10, 2011 08:14PM UTC by comment:5
priority: | low → blocker |
---|
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.