From: Oleg Date: Wed, 9 Jan 2013 09:23:34 +0000 (+0400) Subject: Ref gh-1117: Don't stop on a falsy value in buildFragment. Close gh-1124. X-Git-Tag: 2.0.0b1~17 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=8e6c1ba92faf830d40cafe7a4deb4ad5ab9045fe;p=jquery.git Ref gh-1117: Don't stop on a falsy value in buildFragment. Close gh-1124. --- diff --git a/src/manipulation.js b/src/manipulation.js index c85caa060..5b5d8aec4 100644 --- a/src/manipulation.js +++ b/src/manipulation.js @@ -424,10 +424,14 @@ jQuery.extend({ buildFragment: function( elems, context, scripts, selection ) { var elem, tmp, tag, wrap, contains, j, i = 0, + l = elems.length, fragment = context.createDocumentFragment(), nodes = []; - while ( ( elem = elems[ i++ ] ) || elem === 0 ) { + for ( ; i < l; i++ ) { + elem = elems[ i ]; + + if ( elem || elem === 0 ) { // Add nodes directly if ( jQuery.type( elem ) === "object" ) { @@ -461,6 +465,7 @@ jQuery.extend({ // Support: Webkit, IE tmp.textContent = ""; } + } } // Remove wrapper from fragment @@ -468,7 +473,6 @@ jQuery.extend({ i = 0; while ( (elem = nodes[ i++ ]) ) { - contains = jQuery.contains( elem.ownerDocument, elem ); // #4087 - If origin and destination elements are the same, and this is // that element, do not do anything @@ -476,6 +480,8 @@ jQuery.extend({ continue; } + contains = jQuery.contains( elem.ownerDocument, elem ); + // Append to fragment tmp = getAll( fragment.appendChild( elem ), "script" ); @@ -486,7 +492,6 @@ jQuery.extend({ // Capture executables if ( scripts ) { - j = 0; while ( (elem = tmp[ j++ ]) ) { if ( rscriptType.test( elem.type || "" ) ) { diff --git a/test/unit/manipulation.js b/test/unit/manipulation.js index d2bec12f5..e933a7aff 100644 --- a/test/unit/manipulation.js +++ b/test/unit/manipulation.js @@ -395,7 +395,7 @@ var testAppendForObject = function( valueObj, isFragment ) { var testAppend = function( valueObj ) { - expect( 77 ); + expect( 78 ); testAppendForObject( valueObj, false ); testAppendForObject( valueObj, true ); @@ -469,13 +469,13 @@ var testAppend = function( valueObj ) { jQuery("#table colgroup").append( valueObj("") ); equal( jQuery("#table colgroup col").length, 1, "Append col" ); - jQuery("#form") .append( valueObj("") ) .append( valueObj("") ); t( "Append Select", "#appendSelect1, #appendSelect2", [ "appendSelect1", "appendSelect2" ] ); equal( "Two nodes", jQuery("
").append( "Two", " nodes" ).text(), "Appending two text nodes (#4011)" ); + equal( jQuery("
").append( "1", "", 3 ).text(), "13", "If median is false-like value, subsequent arguments should not be ignored" ); // using contents will get comments regular, text, and comment nodes j = jQuery("#nonnodes").contents();