Bug Tracker

Modify

Ticket #9917 (closed bug: duplicate)

Opened 22 months ago

Last modified 22 months ago

$.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:
Blocking: Blocked by:

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

comment:1 Changed 22 months ago by addyosmani

  • Owner set to anonymous
  • Priority changed from undecided to low
  • Status changed from new to pending
  • Component changed from unfiled to data

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 22 months ago by addyosmani

#9918 is a duplicate of this ticket.

comment:3 Changed 22 months ago by rwaldron

  • Status changed from pending to closed
  • Resolution set to duplicate

comment:4 Changed 22 months ago by rwaldron

Duplicate of #9779.

comment:5 Changed 22 months ago by rwaldron

  • Priority changed from low to blocker

comment:6 Changed 22 months ago by rwaldron

#10016 is a duplicate of this ticket.

Please follow the  bug reporting guidlines and use  jsFiddle when providing test cases and demonstrations instead of pasting the code in the ticket.

View

Add a comment

Modify Ticket

Action
as closed
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.