Skip to content

Commit

Permalink
Fix #14101: $().data() should be undefined, not null
Browse files Browse the repository at this point in the history
  • Loading branch information
gnarf authored and rwaldron committed Nov 6, 2013
1 parent cc19a6b commit 30eee92
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
3 changes: 1 addition & 2 deletions src/data.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,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;

Expand Down
6 changes: 6 additions & 0 deletions test/unit/data.js
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,12 @@ test("jQuery.data(object/flash)", 25, function() {
dataTests( flash );
});

// 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);

Expand Down

0 comments on commit 30eee92

Please sign in to comment.