From: Dave Methvin Date: Fri, 24 Aug 2012 03:25:57 +0000 (-0400) Subject: Fix #12120. Always stack .before/.after, and fix disconnected nodes. X-Git-Tag: 1.8.1~26 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=e2eac3f4d2e7f47b67635704df8e3b6675a91ed6;p=jquery.git Fix #12120. Always stack .before/.after, and fix disconnected nodes. --- diff --git a/src/manipulation.js b/src/manipulation.js index f87e3ca94..67c6c06f0 100644 --- a/src/manipulation.js +++ b/src/manipulation.js @@ -148,10 +148,7 @@ jQuery.fn.extend({ }); } - if ( arguments.length ) { - var set = jQuery.clean( arguments ); - return this.pushStack( jQuery.merge( set, this ), "before", this.selector ); - } + return this.pushStack( jQuery.merge( jQuery.clean( arguments ), this ), "before", this.selector ); }, after: function() { @@ -161,10 +158,7 @@ jQuery.fn.extend({ }); } - if ( arguments.length ) { - var set = jQuery.clean( arguments ); - return this.pushStack( jQuery.merge( this, set ), "after", this.selector ); - } + return this.pushStack( jQuery.merge( this.toArray(), jQuery.clean( arguments ) ), "after", this.selector ); }, // keepData is for internal use only--do not document @@ -721,6 +715,7 @@ jQuery.extend({ // Fix #11356: Clear elements from safeFragment if ( div ) { + div.innerHTML = ""; safe.removeChild( div ); elem = div = safe = null; } diff --git a/test/unit/manipulation.js b/test/unit/manipulation.js index d63b3ff86..15a95864d 100644 --- a/test/unit/manipulation.js +++ b/test/unit/manipulation.js @@ -909,12 +909,13 @@ test("before(Function)", function() { testBefore(manipulationFunctionReturningObj); }); -test("before and after w/ empty object (#10812)", function() { - expect(2); +test("before and after w/ empty object (#10812, #12120)", function() { + expect(3); - var res = jQuery( "#notInTheDocument" ).before( "(" ).after( ")" ); - equal( res.length, 2, "didn't choke on empty object" ); - equal( res.wrapAll("
").parent().text(), "()", "correctly appended text" ); + var res = jQuery("#notInTheDocument").before("(").after(")"); + equal( res.length, 2, "added two elements to the empty object" ); + equal( res.text(), "()", "correctly appended text" ); + equal( res.end().text(), "(", "stacked the previous value" ); }); test("before and after on disconnected node (#10517)", function() {