Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Guard against exceptions when clearing safeChildNodes.

Supplements #11356 and fixes unit test failures in FF 3.6.
  • Loading branch information...
commit 619f0d908a4227d4fd49971d7f9a5290eaffd72d 1 parent e529d91
Rick Waldron rwaldron authored dmethvin committed
Showing with 19 additions and 3 deletions.
  1. +7 −3 src/manipulation.js
  2. +12 −0 test/unit/manipulation.js
10 src/manipulation.js
View
@@ -727,10 +727,14 @@ jQuery.extend({
// to avoid hoarding elements. Fixes #11356
if ( div ) {
div.parentNode.removeChild( div );
- remove = safeChildNodes[ safeChildNodes.length - 1 ];
- if ( remove && remove.parentNode ) {
- remove.parentNode.removeChild( remove );
+ // Guard against -1 index exceptions in FF3.6
+ if ( safeChildNodes.length > 0 ) {
+ remove = safeChildNodes[ safeChildNodes.length - 1 ];
+
+ if ( remove && remove.parentNode ) {
+ remove.parentNode.removeChild( remove );
+ }
}
}
}
12 test/unit/manipulation.js
View
@@ -1740,3 +1740,15 @@ test("jQuery.fragments cache expectations", function() {
equal( fragmentCacheSize(), 12, "12 entries exist in jQuery.fragments, 2" );
});
+
+test("Guard against exceptions when clearing safeChildNodes", function() {
+ expect( 1 );
+
+ var div;
+
+ try {
+ div = jQuery("<div/><hr/><code/><b/>");
+ } catch(e) {}
+
+ ok( div && div.jquery, "Created nodes safely, guarded against exceptions on safeChildNodes[ -1 ]" );
+});
Please sign in to comment.
Something went wrong with that request. Please try again.