Skip to content

Commit

Permalink
Skip id regex check when large html strings are passed to the jQuery …
Browse files Browse the repository at this point in the history
…constructor (#7990).
  • Loading branch information
carpie authored and dmethvin committed Apr 6, 2011
1 parent ceaf093 commit e085673
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
7 changes: 6 additions & 1 deletion src/core.js
Expand Up @@ -96,7 +96,12 @@ jQuery.fn = jQuery.prototype = {
// Handle HTML strings // Handle HTML strings
if ( typeof selector === "string" ) { if ( typeof selector === "string" ) {
// Are we dealing with HTML string or an ID? // Are we dealing with HTML string or an ID?
match = quickExpr.exec( selector ); if ( selector.length > 1024 ) {

This comment has been minimized.

Copy link
@jdalton

jdalton Apr 16, 2011

Member

I am geeking out over the bug and the fix. srsly awesome.

// 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 // Verify a match, and that no context was specified for #id
if ( match && (match[1] || !context) ) { if ( match && (match[1] || !context) ) {
Expand Down
15 changes: 14 additions & 1 deletion test/unit/core.js
Expand Up @@ -469,7 +469,7 @@ test("isWindow", function() {
}); });


test("jQuery('html')", function() { test("jQuery('html')", function() {
expect(15); expect(18);


QUnit.reset(); QUnit.reset();
jQuery.foo = false; jQuery.foo = false;
Expand Down Expand Up @@ -501,6 +501,19 @@ test("jQuery('html')", function() {


ok( jQuery("<div></div>")[0], "Create a div with closing tag." ); ok( jQuery("<div></div>")[0], "Create a div with closing tag." );
ok( jQuery("<table></table>")[0], "Create a table 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() { test("jQuery('html', context)", function() {
Expand Down

0 comments on commit e085673

Please sign in to comment.