]> source.dussan.org Git - jquery.git/commitdiff
Fix #14101: $().data() should be undefined, not null
authorCorey Frang <gnarf37@gmail.com>
Tue, 5 Nov 2013 20:03:28 +0000 (15:03 -0500)
committerRick Waldron <waldron.rick@gmail.com>
Wed, 6 Nov 2013 15:25:12 +0000 (10:25 -0500)
src/data.js
test/unit/data.js

index 63920bb9efcd1b16b4610d1b11f30f251980cc90..8b285d2668d3d90a83b9abcda4447c58f823cefd 100644 (file)
@@ -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;
 
index bf5629644b9ab1b67ea163712e402e01a06732cf..086067cdcbceaf0a8fd176c48f1a4d241f9a05e1 100644 (file)
@@ -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);