Commit 075763b7 authored by Corey Frang's avatar Corey Frang

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

- Backported 30eee925 for 1.x
parent 3c968ce6
......@@ -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 ) {
......
......@@ -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);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment