]> source.dussan.org Git - jquery.git/commitdiff
Guard against exceptions when clearing safeChildNodes.
authorRick Waldron waldron.rick@gmail.com <waldron.rick@gmail.com>
Tue, 6 Mar 2012 15:22:58 +0000 (10:22 -0500)
committerDave Methvin <dave.methvin@gmail.com>
Tue, 6 Mar 2012 17:54:51 +0000 (12:54 -0500)
Supplements #11356 and fixes unit test failures in FF 3.6.

src/manipulation.js
test/unit/manipulation.js

index 159c4c48853b0ace166b66921ce7da71c48c3621..0b42810da3add708be468b53fffc8cc95bb0c7fd 100644 (file)
@@ -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 );
+                                                       }
                                                }
                                        }
                                }
index bfdc1551a7a92a4ab424886de6227eaed38f4e22..18e1b8d67ee185e17b6bdd8c400266bb76b59fff 100644 (file)
@@ -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 ]" );
+});
\ No newline at end of file