Skip to main content

Bug Tracker

Side navigation

#3748 closed bug (fixed)

Opened December 25, 2008 06:35AM UTC

Closed December 30, 2008 11:29AM UTC

[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.

Attachments (0)
Change History (1)

Changed December 30, 2008 11:29AM UTC by flesler comment:1

cc: → cbeyls
component: coredata
resolution: → fixed
status: newclosed

Fixed at [6010-6012]