Skip to content

Commit b5a16ea

Browse files
committed
Merge pull request jquery#412 from rwldrn/9587
jQuery.clone() check destination child nodes are not null. Fixes #9587
2 parents 59936dc + 5c3b9e0 commit b5a16ea

File tree

3 files changed

+18
-2
lines changed

3 files changed

+18
-2
lines changed

src/manipulation.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -564,7 +564,10 @@ jQuery.extend({
564564
// with an element if you are cloning the body and one of the
565565
// elements on the page has a name or id of "length"
566566
for ( i = 0; srcElements[i]; ++i ) {
567-
cloneFixAttributes( srcElements[i], destElements[i] );
567+
// Ensure that the destination node is not null; Fixes #9587
568+
if ( destElements[i] ) {
569+
cloneFixAttributes( srcElements[i], destElements[i] );
570+
}
568571
}
569572
}
570573

@@ -762,4 +765,4 @@ function evalScript( i, elem ) {
762765
}
763766
}
764767

765-
})( jQuery );
768+
})( jQuery );

test/index.html

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,8 @@ <h2 id="qunit-userAgent"></h2>
281281
</div>
282282

283283
<div id="fx-tests"></div>
284+
285+
<div id="no-clone-exception"><object><embed></embed></object></div>
284286
</div>
285287
</body>
286288
</html>

test/unit/manipulation.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1465,3 +1465,14 @@ test("jQuery.buildFragment - plain objects are not a document #8950", function()
14651465
} catch (e) {}
14661466

14671467
});
1468+
1469+
test("jQuery.clone - no exceptions for object elements #9587", function() {
1470+
expect(1);
1471+
1472+
try {
1473+
jQuery("#no-clone-exception").clone();
1474+
ok( true, "cloned with no exceptions" );
1475+
} catch( e ) {
1476+
ok( false, e.message );
1477+
}
1478+
});

0 commit comments

Comments
 (0)