Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

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 2 changed files with 19 additions and 3 deletions. Show diff stats Hide diff stats

  1. +7 3 src/manipulation.js
  2. +12 0 test/unit/manipulation.js
10 src/manipulation.js
@@ -727,10 +727,14 @@ jQuery.extend({
727 727 // to avoid hoarding elements. Fixes #11356
728 728 if ( div ) {
729 729 div.parentNode.removeChild( div );
730   - remove = safeChildNodes[ safeChildNodes.length - 1 ];
731 730
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 + }
734 738 }
735 739 }
736 740 }
12 test/unit/manipulation.js
@@ -1740,3 +1740,15 @@ test("jQuery.fragments cache expectations", function() {
1740 1740
1741 1741 equal( fragmentCacheSize(), 12, "12 entries exist in jQuery.fragments, 2" );
1742 1742 });
  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 comments on commit 619f0d9

Please sign in to comment.
Something went wrong with that request. Please try again.