Bug Tracker

Opened 8 years ago

Closed 8 years ago

#3748 closed bug (fixed)

[1.3b1] jQuery.data() API changed and does not allow to store "" or null as values anymore

Reported by: cbeyls Owned by:
Priority: major Milestone: 1.3
Component: data Version:
Keywords: Cc: cbeyls
Blocked by: Blocking:

Description

I'm testing jQuery 1.3 beta 1.

In jQuery 1.2.6, it was possible to store empty strings ("") and null as values for jQuery.data(). If the value was not set or unset, jQuery.data() would return undefined.

Example:

var value, el = $("#hello")[0];
value = jQuery.data(el, "test");
// value === undefined

jQuery.data(el, "test", "");
value = jQuery.data(el, "test");
// value === ""

jQuery.data(el, "test", null);
value = jQuery.data(el, "test");
// value === null

jQuery.removeData(el, "test");
value = jQuery.data(el, "test");
// value === undefined

However, in jQuery 1.3 beta 1, storing an empty string ("") makes jQuery.data() return null. Furthermore, if the value was not defined, it also returns null instead of undefined, so it is not possible to know if a null value was actually stored or if no value was stored at all, which makes it practically impossible to store null as value as well.

Same example, different values with 1.3b1:

var value, el = $("#hello")[0];
value = jQuery.data(el, "test");
// value === null

jQuery.data(el, "test", "");
value = jQuery.data(el, "test");
// value === null

jQuery.data(el, "test", null);
value = jQuery.data(el, "test");
// value === null

jQuery.removeData(el, "test");
value = jQuery.data(el, "test");
// value === null

This means that code which stores empty string values will break because it will get a null back instead of a string, and code which relied on the return value being different than undefined to confirm that it was set will also break.

Change History (1)

comment:1 Changed 8 years ago by flesler

  • Cc cbeyls added
  • Component changed from core to data
  • Resolution set to fixed
  • Status changed from new to closed

Fixed at [6010-6012]

Note: See TracTickets for help on using tickets.