]> source.dussan.org Git - jquery.git/commitdiff
Skip id regex check when large html strings are passed to the jQuery constructor...
authorcarpie <elcarpie@gmail.com>
Wed, 19 Jan 2011 23:37:31 +0000 (17:37 -0600)
committerDave Methvin <dave.methvin@gmail.com>
Wed, 6 Apr 2011 03:18:35 +0000 (23:18 -0400)
src/core.js
test/unit/core.js

index f19de96d01da062d03e32b55c1f3405fe5bdda70..a893fc9b3382b0d046bb061d9cd40acae431b6b5 100644 (file)
@@ -96,7 +96,12 @@ jQuery.fn = jQuery.prototype = {
                // Handle HTML strings
                if ( typeof selector === "string" ) {
                        // Are we dealing with HTML string or an ID?
-                       match = quickExpr.exec( selector );
+                       if ( selector.length > 1024 ) {
+                               // Assume very large strings are HTML and skip the regex check
+                               match = [ null, selector, null ];
+                       } else {
+                               match = quickExpr.exec( selector );
+                       }
 
                        // Verify a match, and that no context was specified for #id
                        if ( match && (match[1] || !context) ) {
index a8da85fc25fc44f267d4afe97e5b5b904648d0b4..03325ab77a31a14fc751731bcdd32d0610ce7c23 100644 (file)
@@ -469,7 +469,7 @@ test("isWindow", function() {
 });
 
 test("jQuery('html')", function() {
-       expect(15);
+       expect(18);
 
        QUnit.reset();
        jQuery.foo = false;
@@ -501,6 +501,19 @@ test("jQuery('html')", function() {
 
        ok( jQuery("<div></div>")[0], "Create a div with closing tag." );
        ok( jQuery("<table></table>")[0], "Create a table with closing tag." );
+
+       // Test very large html string #7990
+       var i;
+       var li = '<li>very large html string</li>';
+       var html = ['<ul>'];
+       for ( i = 0; i < 50000; i += 1 ) {
+               html.push(li);
+       }
+       html.push('</ul>');
+       html = jQuery(html.join(''))[0];
+       equals( html.nodeName.toUpperCase(), 'UL');
+       equals( html.firstChild.nodeName.toUpperCase(), 'LI');
+       equals( html.childNodes.length, 50000 );
 });
 
 test("jQuery('html', context)", function() {