From 14b88f6019cd467c35a2c9e845740a61c153525e Mon Sep 17 00:00:00 2001 From: John Resig Date: Wed, 17 Oct 2007 23:35:57 +0000 Subject: [PATCH] Fix for bug #1546 where a deep copy was attempted of DOM elements (which isn't needed). --- src/core.js | 2 +- test/unit/core.js | 9 +++++---- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/core.js b/src/core.js index d396ee95a..3aea325cd 100644 --- a/src/core.js +++ b/src/core.js @@ -534,7 +534,7 @@ jQuery.extend = jQuery.fn.extend = function() { continue; // Recurse if we're merging object values - if ( deep && typeof options[ name ] == "object" && target[ name ] ) + if ( deep && typeof options[ name ] == "object" && target[ name ] && !options[ name ].nodeType ) jQuery.extend( target[ name ], options[ name ] ); // Don't bring in undefined values diff --git a/test/unit/core.js b/test/unit/core.js index 7280ab900..f5fc895a4 100644 --- a/test/unit/core.js +++ b/test/unit/core.js @@ -778,7 +778,7 @@ test("is(String)", function() { }); test("$.extend(Object, Object)", function() { - expect(10); + expect(11); var settings = { xnumber1: 5, xnumber2: 7, xstring1: "peter", xstring2: "pan" }, options = { xnumber2: 1, xstring2: "x", xxx: "newstring" }, @@ -786,9 +786,9 @@ test("$.extend(Object, Object)", function() { merged = { xnumber1: 5, xnumber2: 1, xstring1: "peter", xstring2: "x", xxx: "newstring" }, deep1 = { foo: { bar: true } }, deep1copy = { foo: { bar: true } }, - deep2 = { foo: { baz: true } }, - deep2copy = { foo: { baz: true } }, - deepmerged = { foo: { bar: true, baz: true } }; + deep2 = { foo: { baz: true }, foo2: document }, + deep2copy = { foo: { baz: true }, foo2: document }, + deepmerged = { foo: { bar: true, baz: true }, foo2: document }; jQuery.extend(settings, options); isObj( settings, merged, "Check if extended: settings must be extended" ); @@ -801,6 +801,7 @@ test("$.extend(Object, Object)", function() { jQuery.extend(true, deep1, deep2); isObj( deep1.foo, deepmerged.foo, "Check if foo: settings must be extended" ); 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" ); var defaults = { xnumber1: 5, xnumber2: 7, xstring1: "peter", xstring2: "pan" }, defaultsCopy = { xnumber1: 5, xnumber2: 7, xstring1: "peter", xstring2: "pan" }, -- 2.39.5