Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Follow-up for gh-1117 #1124

Closed
wants to merge 3 commits into from

2 participants

@markelog
Collaborator

If median argument for jQuery.fn.append and alike methods is false-like value, subsequent arguments should not be ignored

/cc @gibson042, @dmethvin

src/manipulation.js
@@ -427,7 +427,8 @@ jQuery.extend({
fragment = context.createDocumentFragment(),
nodes = [];
- while ( ( elem = elems[ i++ ] ) || elem === 0 ) {
+ for ( ; (elem = elems[ i ]) != null; i++ ) {
@gibson042 Collaborator

Let's just go all the way back to for ( ; i < l; i++ ) { here.

@markelog Collaborator
markelog added a note

ok!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@gibson042 gibson042 closed this in 8e6c1ba
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jan 9, 2013
  1. @markelog

    If median argument for jQuery.fn.append and alike methods is false-li…

    markelog authored
    …ke value, subsequent arguments should not be ignored
  2. @markelog

    Move contains check

    markelog authored
  3. @markelog

    Use more frequent for idiom

    markelog authored
This page is out of date. Refresh to see the latest.
Showing with 10 additions and 5 deletions.
  1. +8 −3 src/manipulation.js
  2. +2 −2 test/unit/manipulation.js
View
11 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 || "" ) ) {
View
4 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("<col/>") );
equal( jQuery("#table colgroup col").length, 1, "Append col" );
-
jQuery("#form")
.append( valueObj("<select id='appendSelect1'></select>") )
.append( valueObj("<select id='appendSelect2'><option>Test</option></select>") );
t( "Append Select", "#appendSelect1, #appendSelect2", [ "appendSelect1", "appendSelect2" ] );
equal( "Two nodes", jQuery("<div />").append( "Two", " nodes" ).text(), "Appending two text nodes (#4011)" );
+ equal( jQuery("<div />").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();
Something went wrong with that request. Please try again.