Change check for skipping the initial quickExpr RegExp check. Fixes #8984.

This commit is contained in:
John Resig 2011-05-02 13:14:13 -04:00
parent f1392d8208
commit 86aa764f0b
2 changed files with 15 additions and 3 deletions

View file

@ -96,9 +96,10 @@ 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?
if ( selector.length > 1024 ) { if ( selector.charAt(0) === "<" || selector.charAt( selector.length - 1 ) === ">" ) {
// Assume very large strings are HTML and skip the regex check // Assume that strings that start and end with <> are HTML and skip the regex check
match = [ null, selector, null ]; match = [ null, selector, null ];
} else { } else {
match = quickExpr.exec( selector ); match = quickExpr.exec( selector );
} }

View file

@ -12,7 +12,7 @@ test("Basic requirements", function() {
}); });
test("jQuery()", function() { test("jQuery()", function() {
expect(25); expect(29);
// Basic constructor's behavior // Basic constructor's behavior
@ -96,6 +96,17 @@ test("jQuery()", function() {
// manually clean up detached elements // manually clean up detached elements
elem.remove(); 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() { test("selector state", function() {