Skip to content

Commit

Permalink
Fix #11291. Always clone XML docs with a genuine .cloneNode().
Browse files Browse the repository at this point in the history
  • Loading branch information
Arne de Bree authored and dmethvin committed Feb 10, 2012
1 parent 96bb57d commit bf7a4df
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/manipulation.js
Expand Up @@ -24,7 +24,7 @@ var nodeNames = "abbr|article|aside|audio|bdi|canvas|data|datalist|details|figca
rhtml = /<|&#?\w+;/, rhtml = /<|&#?\w+;/,
rnoInnerhtml = /<(?:script|style)/i, rnoInnerhtml = /<(?:script|style)/i,
rnocache = /<(?:script|object|embed|option|style)/i, rnocache = /<(?:script|object|embed|option|style)/i,
rnoshimcache = new RegExp("<(?:" + nodeNames + ")", "i"), rnoshimcache = new RegExp("<(?:" + nodeNames + ")[\\s/>]", "i"),
// checked="checked" or checked // checked="checked" or checked
rchecked = /checked\s*(?:[^=]|=\s*.checked.)/i, rchecked = /checked\s*(?:[^=]|=\s*.checked.)/i,
rscriptType = /\/(java|ecma)script/i, rscriptType = /\/(java|ecma)script/i,
Expand Down Expand Up @@ -461,7 +461,7 @@ function cloneFixAttributes( src, dest ) {
// Event data gets referenced instead of copied if the expando // Event data gets referenced instead of copied if the expando
// gets copied too // gets copied too
dest.removeAttribute( jQuery.expando ); dest.removeAttribute( jQuery.expando );

// Clear flags for bubbling special change/submit events, they must // Clear flags for bubbling special change/submit events, they must
// be reattached when the newly cloned events are first activated // be reattached when the newly cloned events are first activated
dest.removeAttribute( "_submit_attached" ); dest.removeAttribute( "_submit_attached" );
Expand Down Expand Up @@ -590,7 +590,7 @@ jQuery.extend({
destElements, destElements,
i, i,
// IE<=8 does not properly clone detached, unknown element nodes // IE<=8 does not properly clone detached, unknown element nodes
clone = jQuery.support.html5Clone || !rnoshimcache.test( "<" + elem.nodeName ) ? clone = jQuery.support.html5Clone || jQuery.isXMLDoc(elem) || !rnoshimcache.test( "<" + elem.nodeName + ">" ) ?
elem.cloneNode( true ) : elem.cloneNode( true ) :
shimCloneNode( elem ); shimCloneNode( elem );


Expand Down
10 changes: 10 additions & 0 deletions test/unit/manipulation.js
Expand Up @@ -1218,6 +1218,16 @@ test("clone() on XML nodes", function() {
}); });
} }


test("clone() on local XML nodes with html5 nodename", function() {
expect(2);

var $xmlDoc = jQuery( jQuery.parseXML( "<root><meter /></root>" ) ),
$meter = $xmlDoc.find( "meter" ).clone();

equal( $meter[0].nodeName, "meter", "Check if nodeName was not changed due to cloning" );
equal( $meter[0].nodeType, 1, "Check if nodeType is not changed due to cloning" );
} );

test("html(undefined)", function() { test("html(undefined)", function() {
expect(1); expect(1);
equal( jQuery("#foo").html("<i>test</i>").html(undefined).html().toLowerCase(), "<i>test</i>", ".html(undefined) is chainable (#5571)" ); equal( jQuery("#foo").html("<i>test</i>").html(undefined).html().toLowerCase(), "<i>test</i>", ".html(undefined) is chainable (#5571)" );
Expand Down

0 comments on commit bf7a4df

Please sign in to comment.