Skip to content
Permalink
Browse files

Merge pull request #412 from rwldrn/9587

jQuery.clone() check destination child nodes are not null. Fixes #9587
  • Loading branch information...
dmethvin committed Aug 4, 2011
2 parents 59936dc + 5c3b9e0 commit b5a16ead1ae2b7449c442c151299f9f456c03942
Showing with 18 additions and 2 deletions.
  1. +5 −2 src/manipulation.js
  2. +2 −0 test/index.html
  3. +11 −0 test/unit/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 );
})( jQuery );
@@ -281,6 +281,8 @@ <h2 id="qunit-userAgent"></h2>
</div>

<div id="fx-tests"></div>

<div id="no-clone-exception"><object><embed></embed></object></div>
</div>
</body>
</html>
@@ -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 );
}
});

1 comment on commit b5a16ea

@ghost

This comment has been minimized.

Copy link

ghost commented on b5a16ea Aug 11, 2011

Cloning error still occurs in IE9 (http://bugs.jquery.com/ticket/9587). We were able to fix this by adding the same destElements condition a couple of lines further down before calling cloneCopyEvent

for ( i = 0; srcElements[i]; ++i ) {
  if ( destElements[i] ) {
    cloneCopyEvent( srcElements[i], destElements[i] );
  }
}
Please sign in to comment.
You can’t perform that action at this time.