From 30eee925dbc9f8d465ccf064f48c24061ffdc378 Mon Sep 17 00:00:00 2001 From: Corey Frang Date: Tue, 5 Nov 2013 15:03:28 -0500 Subject: [PATCH] Fix #14101: $().data() should be undefined, not null --- src/data.js | 3 +-- test/unit/data.js | 6 ++++++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/data.js b/src/data.js index 63920bb9e..8b285d266 100644 --- a/src/data.js +++ b/src/data.js @@ -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; diff --git a/test/unit/data.js b/test/unit/data.js index bf5629644..086067cdc 100644 --- a/test/unit/data.js +++ b/test/unit/data.js @@ -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); -- 2.39.5