Skip to content

Commit 619f0d9

Browse files
rwaldrondmethvin
authored andcommitted
Guard against exceptions when clearing safeChildNodes.
Supplements #11356 and fixes unit test failures in FF 3.6.
1 parent e529d91 commit 619f0d9

File tree

2 files changed

+19
-3
lines changed

2 files changed

+19
-3
lines changed

src/manipulation.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -727,10 +727,14 @@ jQuery.extend({
727727
// to avoid hoarding elements. Fixes #11356
728728
if ( div ) {
729729
div.parentNode.removeChild( div );
730-
remove = safeChildNodes[ safeChildNodes.length - 1 ];
731730

732-
if ( remove && remove.parentNode ) {
733-
remove.parentNode.removeChild( remove );
731+
// Guard against -1 index exceptions in FF3.6
732+
if ( safeChildNodes.length > 0 ) {
733+
remove = safeChildNodes[ safeChildNodes.length - 1 ];
734+
735+
if ( remove && remove.parentNode ) {
736+
remove.parentNode.removeChild( remove );
737+
}
734738
}
735739
}
736740
}

test/unit/manipulation.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1740,3 +1740,15 @@ test("jQuery.fragments cache expectations", function() {
17401740

17411741
equal( fragmentCacheSize(), 12, "12 entries exist in jQuery.fragments, 2" );
17421742
});
1743+
1744+
test("Guard against exceptions when clearing safeChildNodes", function() {
1745+
expect( 1 );
1746+
1747+
var div;
1748+
1749+
try {
1750+
div = jQuery("<div/><hr/><code/><b/>");
1751+
} catch(e) {}
1752+
1753+
ok( div && div.jquery, "Created nodes safely, guarded against exceptions on safeChildNodes[ -1 ]" );
1754+
});

0 commit comments

Comments
 (0)