]> source.dussan.org Git - jquery.git/commitdiff
core: Fixed #2605: .data() now accepts null as a value.
authorScott González <scott.gonzalez@gmail.com>
Sat, 3 May 2008 01:51:55 +0000 (01:51 +0000)
committerScott González <scott.gonzalez@gmail.com>
Sat, 3 May 2008 01:51:55 +0000 (01:51 +0000)
src/core.js
test/unit/core.js

index b6bdc1d0c94f6031554b10b5647bfe03a724c283..f6f0bd592cb416affed841b5cd87116e81b7e0d6 100644 (file)
@@ -465,13 +465,13 @@ jQuery.fn = jQuery.prototype = {
                var parts = key.split(".");
                parts[1] = parts[1] ? "." + parts[1] : "";
 
-               if ( value == null ) {
+               if ( value === undefined ) {
                        var data = this.triggerHandler("getData" + parts[1] + "!", [parts[0]]);
                        
-                       if ( data == undefined && this.length )
+                       if ( data === undefined && this.length )
                                data = jQuery.data( this[0], key );
 
-                       return data == null && parts[1] ?
+                       return data === undefined && parts[1] ?
                                this.data( parts[0] ) :
                                data;
                } else
index e6321a6436bf385249b8318228314c9a98a80f30..9f46dd4d4d2227e699b3224dd0ed3b4f2f009b0f 100644 (file)
@@ -1412,16 +1412,21 @@ test("$.data", function() {
 });\r
 \r
 test(".data()", function() {\r
-       expect(16);\r
+       expect(18);\r
        var div = $("#foo");\r
        ok( div.data("test") == undefined, "Check for no data exists" );\r
        div.data("test", "success");\r
        ok( div.data("test") == "success", "Check for added data" );\r
        div.data("test", "overwritten");\r
        ok( div.data("test") == "overwritten", "Check for overwritten data" );\r
-\r
+       div.data("test", undefined);\r
+       ok( div.data("test") == "overwritten", "Check that data wasn't removed");\r
+       div.data("test", null);\r
+       ok( div.data("test") === null, "Check for null data");\r
+       \r
+       div.data("test", "overwritten");\r
        var hits = {test:0}, gets = {test:0};\r
-\r
+       \r
        div\r
                .bind("setData",function(e,key,value){ hits[key] += value; })\r
                .bind("setData.foo",function(e,key,value){ hits[key] += value; })\r