From 5c3b9e0c24dbb31245e9266dcd20fface92747eb Mon Sep 17 00:00:00 2001 From: rwldrn Date: Wed, 15 Jun 2011 11:14:52 -0400 Subject: [PATCH] jQuery.clone() check that destination child nodes are not null. Fixes #9587 --- src/manipulation.js | 7 +++++-- test/index.html | 2 ++ test/unit/manipulation.js | 11 +++++++++++ 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/src/manipulation.js b/src/manipulation.js index 439b9596b..2f41feb9a 100644 --- a/src/manipulation.js +++ b/src/manipulation.js @@ -564,7 +564,10 @@ jQuery.extend({ // with an element if you are cloning the body and one of the // elements on the page has a name or id of "length" for ( i = 0; srcElements[i]; ++i ) { - cloneFixAttributes( srcElements[i], destElements[i] ); + // Ensure that the destination node is not null; Fixes #9587 + if ( destElements[i] ) { + cloneFixAttributes( srcElements[i], destElements[i] ); + } } } @@ -762,4 +765,4 @@ function evalScript( i, elem ) { } } -})( jQuery ); \ No newline at end of file +})( jQuery ); diff --git a/test/index.html b/test/index.html index 4b4c98552..f3f235e09 100644 --- a/test/index.html +++ b/test/index.html @@ -281,6 +281,8 @@ Z
+ +
diff --git a/test/unit/manipulation.js b/test/unit/manipulation.js index b9bc75873..4017cf196 100644 --- a/test/unit/manipulation.js +++ b/test/unit/manipulation.js @@ -1465,3 +1465,14 @@ test("jQuery.buildFragment - plain objects are not a document #8950", function() } catch (e) {} }); + +test("jQuery.clone - no exceptions for object elements #9587", function() { + expect(1); + + try { + jQuery("#no-clone-exception").clone(); + ok( true, "cloned with no exceptions" ); + } catch( e ) { + ok( false, e.message ); + } +});