Skip to content

Commit

Permalink
Change check for skipping the initial quickExpr RegExp check. Fixes #…
Browse files Browse the repository at this point in the history
…8984.
  • Loading branch information
jeresig committed May 2, 2011
1 parent f1392d8 commit 86aa764
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
5 changes: 3 additions & 2 deletions src/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,10 @@ jQuery.fn = jQuery.prototype = {
// Handle HTML strings
if ( typeof selector === "string" ) {
// Are we dealing with HTML string or an ID?
if ( selector.length > 1024 ) {
// Assume very large strings are HTML and skip the regex check
if ( selector.charAt(0) === "<" || selector.charAt( selector.length - 1 ) === ">" ) {
// Assume that strings that start and end with <> are HTML and skip the regex check
match = [ null, selector, null ];

} else {
match = quickExpr.exec( selector );
}
Expand Down
13 changes: 12 additions & 1 deletion test/unit/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ test("Basic requirements", function() {
});

test("jQuery()", function() {
expect(25);
expect(29);

// Basic constructor's behavior

Expand Down Expand Up @@ -96,6 +96,17 @@ test("jQuery()", function() {

// manually clean up detached elements
elem.remove();

equals( jQuery(" <div/> ").length, 1, "Make sure whitespace is trimmed." );
equals( jQuery(" a<div/>b ").length, 1, "Make sure whitespace and other characters are trimmed." );

var long = "";
for ( var i = 0; i < 128; i++ ) {
long += "12345678";
}

equals( jQuery(" <div>" + long + "</div> ").length, 1, "Make sure whitespace is trimmed on long strings." );
equals( jQuery(" a<div>" + long + "</div>b ").length, 1, "Make sure whitespace and other characters are trimmed on long strings." );
});

test("selector state", function() {
Expand Down

0 comments on commit 86aa764

Please sign in to comment.