Skip to content
Permalink
Browse files

Fix #12347 and #12384. Use a fresh div in jQuery.clean each time.

Regression was introduced in 22ad872 most likely because the clown who fixed http://bugs.jquery.com/ticket/4011 didn't add a unit test.
  • Loading branch information
dmethvin committed Aug 28, 2012
1 parent 7d076f5 commit b6a7d022eeb8c2cb0b065a311e53f9ea98554600
Showing with 22 additions and 8 deletions.
  1. +8 −8 src/manipulation.js
  2. +14 −0 test/unit/manipulation.js
@@ -638,8 +638,8 @@ jQuery.extend({
},

clean: function( elems, context, fragment, scripts ) {
var j, safe, elem, tag, wrap, depth, div, hasBody, tbody, len, handleScript, jsTags,
i = 0,
var i, j, elem, tag, wrap, depth, div, hasBody, tbody, len, handleScript, jsTags,
safe = context === document && safeFragment,
ret = [];

// Ensure that context is a document
@@ -648,7 +648,7 @@ jQuery.extend({
}

// Use the already-created safe fragment if context permits
for ( safe = context === document && safeFragment; (elem = elems[i]) != null; i++ ) {
for ( i = 0; (elem = elems[i]) != null; i++ ) {
if ( typeof elem === "number" ) {
elem += "";
}
@@ -664,7 +664,8 @@ jQuery.extend({
} else {
// Ensure a safe container in which to render the html
safe = safe || createSafeFragment( context );
div = div || safe.appendChild( context.createElement("div") );
div = context.createElement("div");
safe.appendChild( div );

// Fix "XHTML"-style tags in all browsers
elem = elem.replace(rxhtmlTag, "<$1></$2>");
@@ -707,21 +708,20 @@ jQuery.extend({

elem = div.childNodes;

// Remember the top-level container for proper cleanup
div = safe.lastChild;
// Take out of fragment container (we need a fresh div each time)
div.parentNode.removeChild( div );

This comment has been minimized.

Copy link
@dmethvin

dmethvin Aug 29, 2012

Author Member

Hmmm, could have done safe.removeChild( div ) here I think.

}
}

if ( elem.nodeType ) {
ret.push( elem );
} else {
ret = jQuery.merge( ret, elem );
jQuery.merge( ret, elem );
}
}

// Fix #11356: Clear elements from safeFragment
if ( div ) {
safe.removeChild( div );
elem = div = safe = null;
}

@@ -1934,6 +1934,20 @@ test("checked state is cloned with clone()", function(){
equal( jQuery(elem).clone().attr("id","clone")[0].checked, true, "Checked true state correctly cloned" );
});

test("manipulate mixed jQuery and text (#12384, #12346)", function() {
expect(2);

var div = jQuery("<div>a</div>").append( "&nbsp;", jQuery("<span>b</span>"), "&nbsp;", jQuery("<span>c</span>") ),
nbsp = String.fromCharCode(160);
equal( div.text(), "a" + nbsp + "b" + nbsp+ "c", "Appending mixed jQuery with text nodes" );

div = jQuery("<div><div></div></div>")
.find("div")
.after("<p>a</p>", "<p>b</p>" )
.parent();
equal( div.find("*").length, 3, "added 2 paragraphs after inner div" );
});

testIframeWithCallback( "buildFragment works even if document[0] is iframe's window object in IE9/10 (#12266)", "manipulation/iframe-denied.html", function( test ) {
expect( 1 );

1 comment on commit b6a7d02

@dmethvin

This comment has been minimized.

Copy link
Member Author

dmethvin commented on b6a7d02 Aug 28, 2012

Actual ticket is #12346

Please sign in to comment.
You can’t perform that action at this time.