Fix #14101: $().data() should be undefined, not null

- Backported 30eee925db for 1.x
This commit is contained in:
Corey Frang 2013-11-05 15:03:28 -05:00
parent 3c968ce65d
commit 075763b71a
2 changed files with 8 additions and 3 deletions

View File

@ -272,8 +272,7 @@ jQuery.extend({
jQuery.fn.extend({
data: function( key, value ) {
var i, name,
data = null,
var i, name, data,
elem = this[0],
attrs = elem && elem.attributes;
@ -319,7 +318,7 @@ jQuery.fn.extend({
// Gets one value
// Try to fetch any internally stored data first
elem ? dataAttr( elem, key, jQuery.data( elem, key ) ) : null;
elem ? dataAttr( elem, key, jQuery.data( elem, key ) ) : undefined;
},
removeData: function( key ) {

View File

@ -164,6 +164,12 @@ test("jQuery.acceptData", function() {
ok( !jQuery.acceptData( document.createTextNode("") ), "text" );
});
// attempting to access the data of an undefined jQuery element should be undefined
test("jQuery().data() === undefined (#14101)", 2, function() {
strictEqual(jQuery().data(), undefined);
strictEqual(jQuery().data("key"), undefined);
});
test(".data()", function() {
expect(5);