From 619f0d908a4227d4fd49971d7f9a5290eaffd72d Mon Sep 17 00:00:00 2001 From: "Rick Waldron waldron.rick@gmail.com" Date: Tue, 6 Mar 2012 10:22:58 -0500 Subject: [PATCH] Guard against exceptions when clearing safeChildNodes. Supplements #11356 and fixes unit test failures in FF 3.6. --- src/manipulation.js | 10 +++++++--- test/unit/manipulation.js | 12 ++++++++++++ 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/src/manipulation.js b/src/manipulation.js index 159c4c488..0b42810da 100644 --- a/src/manipulation.js +++ b/src/manipulation.js @@ -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 ); + } } } } diff --git a/test/unit/manipulation.js b/test/unit/manipulation.js index bfdc1551a..18e1b8d67 100644 --- a/test/unit/manipulation.js +++ b/test/unit/manipulation.js @@ -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("

"); + } catch(e) {} + + ok( div && div.jquery, "Created nodes safely, guarded against exceptions on safeChildNodes[ -1 ]" ); +}); \ No newline at end of file -- 2.39.5