From e0856738e6151368cffc963800e06ebcc0bbc314 Mon Sep 17 00:00:00 2001 From: carpie Date: Wed, 19 Jan 2011 17:37:31 -0600 Subject: [PATCH] Skip id regex check when large html strings are passed to the jQuery constructor (#7990). --- src/core.js | 7 ++++++- test/unit/core.js | 15 ++++++++++++++- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/src/core.js b/src/core.js index f19de96d..a893fc9b 100644 --- a/src/core.js +++ b/src/core.js @@ -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) ) { diff --git a/test/unit/core.js b/test/unit/core.js index a8da85fc..03325ab7 100644 --- a/test/unit/core.js +++ b/test/unit/core.js @@ -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("
")[0], "Create a div with closing tag." ); ok( jQuery("
")[0], "Create a table with closing tag." ); + + // Test very large html string #7990 + var i; + var li = '
  • very large html string
  • '; + var html = [''); + 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() {