]> source.dussan.org Git - jquery.git/commitdiff
Fixes jQuery.fragments cache and adds tests. Fixes #10682 579/head
authorRick Waldron <waldron.rick@gmail.com>
Sun, 6 Nov 2011 03:04:09 +0000 (23:04 -0400)
committerRick Waldron <waldron.rick@gmail.com>
Sun, 6 Nov 2011 03:06:53 +0000 (23:06 -0400)
src/manipulation.js
test/unit/manipulation.js

index 6e77e2daa3144dffea340207c8aff2e4c8e05a48..134756544314a65cae6938b1edca06a5afcc8600 100644 (file)
@@ -480,7 +480,7 @@ jQuery.buildFragment = function( args, nodes, scripts ) {
        // Lastly, IE6,7,8 will not correctly reuse cached fragments that were created from unknown elems #10501
        if ( args.length === 1 && typeof first === "string" && first.length < 512 && doc === document &&
                first.charAt(0) === "<" && !rnocache.test( first ) &&
-               (jQuery.support.checkClone || !rchecked.test( first )) &&
+               (jQuery.support.checkClone || !rchecked.test( first )) ||
                (!jQuery.support.unknownElems && rnoshimcache.test( first )) ) {
 
                cacheable = true;
index e8c7cd72a8a4f6f5533475f49bd4c9face3cd15b..59dc162255aa10f5cf71ccf6c6b14509b4a7bc8e 100644 (file)
@@ -1531,3 +1531,51 @@ test("jQuery.clone - no exceptions for object elements #9587", function() {
                ok( false, e.message );
        }
 });
+
+test("jQuery.fragments cache expectations", function() {
+
+       expect( 10 );
+
+       jQuery.fragments = {};
+
+       function fragmentCacheSize() {
+               var n = 0, c;
+
+               for ( c in jQuery.fragments ) {
+                       n++;
+               }
+               return n;
+       }
+
+       jQuery("<li></li>");
+       jQuery("<li>?</li>");
+       jQuery("<li>whip</li>");
+       jQuery("<li>it</li>");
+       jQuery("<li>good</li>");
+       jQuery("<div></div>");
+       jQuery("<div><div><span></span></div></div>");
+       jQuery("<tr><td></td></tr>");
+       jQuery("<tr><td></tr>");
+       jQuery("<li>aaa</li>");
+       jQuery("<ul><li>?</li></ul>");
+       jQuery("<div><p>arf</p>nnn</div>");
+       jQuery("<div><p>dog</p>?</div>");
+       jQuery("<span><span>");
+
+       equal( fragmentCacheSize(), 12, "12 entries exist in jQuery.fragments, 1" );
+
+       jQuery.each( [
+               "<tr><td></td></tr>",
+               "<ul><li>?</li></ul>",
+               "<div><p>dog</p>?</div>",
+               "<span><span>"
+       ], function( i, frag ) {
+
+               jQuery( frag );
+
+               equal( jQuery.fragments[ frag ].nodeType, 11, "Second call with " + frag + " creates a cached DocumentFragment, has nodeType 11" );
+               ok( jQuery.fragments[ frag ].childNodes.length, "Second call with " + frag + " creates a cached DocumentFragment, has childNodes with length" );
+       });
+
+       equal( fragmentCacheSize(), 12, "12 entries exist in jQuery.fragments, 2" );
+});
\ No newline at end of file