From f8698395acbe428bd7c3dd6dd5700a0c660deeab Mon Sep 17 00:00:00 2001 From: =?utf8?q?Scott=20Gonz=C3=A1lez?= Date: Sat, 3 May 2008 01:51:55 +0000 Subject: [PATCH] core: Fixed #2605: .data() now accepts null as a value. --- src/core.js | 6 +++--- test/unit/core.js | 11 ++++++++--- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/src/core.js b/src/core.js index b6bdc1d0c..f6f0bd592 100644 --- a/src/core.js +++ b/src/core.js @@ -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 diff --git a/test/unit/core.js b/test/unit/core.js index e6321a643..9f46dd4d4 100644 --- a/test/unit/core.js +++ b/test/unit/core.js @@ -1412,16 +1412,21 @@ test("$.data", function() { }); test(".data()", function() { - expect(16); + expect(18); var div = $("#foo"); ok( div.data("test") == undefined, "Check for no data exists" ); div.data("test", "success"); ok( div.data("test") == "success", "Check for added data" ); div.data("test", "overwritten"); ok( div.data("test") == "overwritten", "Check for overwritten data" ); - + div.data("test", undefined); + ok( div.data("test") == "overwritten", "Check that data wasn't removed"); + div.data("test", null); + ok( div.data("test") === null, "Check for null data"); + + div.data("test", "overwritten"); var hits = {test:0}, gets = {test:0}; - + div .bind("setData",function(e,key,value){ hits[key] += value; }) .bind("setData.foo",function(e,key,value){ hits[key] += value; }) -- 2.39.5