core: Fixed #2600: jQuery.extend no longer skips over null properties.

This commit is contained in:
Scott González 2008-05-02 19:49:41 +00:00
parent 87758bbe69
commit 35c68b4578
2 changed files with 13 additions and 3 deletions

View file

@ -587,7 +587,7 @@ jQuery.extend = jQuery.fn.extend = function() {
target[ name ] = jQuery.extend( deep, src, copy ); target[ name ] = jQuery.extend( deep, src, copy );
// Don't bring in undefined values // Don't bring in undefined values
else if ( copy != undefined ) else if ( copy !== undefined )
target[ name ] = copy; target[ name ] = copy;
} }

View file

@ -1025,7 +1025,7 @@ test("is(String)", function() {
}); });
test("$.extend(Object, Object)", function() { test("$.extend(Object, Object)", function() {
expect(17); expect(20);
var settings = { xnumber1: 5, xnumber2: 7, xstring1: "peter", xstring2: "pan" }, var settings = { xnumber1: 5, xnumber2: 7, xstring1: "peter", xstring2: "pan" },
options = { xnumber2: 1, xstring2: "x", xxx: "newstring" }, options = { xnumber2: 1, xstring2: "x", xxx: "newstring" },
@ -1050,6 +1050,16 @@ test("$.extend(Object, Object)", function() {
isObj( deep2.foo, deep2copy.foo, "Check if not deep2: options must not be modified" ); isObj( deep2.foo, deep2copy.foo, "Check if not deep2: options must not be modified" );
equals( deep1.foo2, document, "Make sure that a deep clone was not attempted on the document" ); equals( deep1.foo2, document, "Make sure that a deep clone was not attempted on the document" );
var nullUndef;
nullUndef = jQuery.extend({}, options, { xnumber2: null });
ok( nullUndef.xnumber2 === null, "Check to make sure null values are copied");
nullUndef = jQuery.extend({}, options, { xnumber2: undefined });
ok( nullUndef.xnumber2 === options.xnumber2, "Check to make sure undefined values are not copied");
nullUndef = jQuery.extend({}, options, { xnumber0: null });
ok( nullUndef.xnumber0 === null, "Check to make sure null values are inserted");
var target = {}; var target = {};
var recursive = { foo:target, bar:5 }; var recursive = { foo:target, bar:5 };
jQuery.extend(true, target, recursive); jQuery.extend(true, target, recursive);