From 86aa764f0b7b659fbd8eec9333d22c3a79bdfcd5 Mon Sep 17 00:00:00 2001 From: John Resig Date: Mon, 2 May 2011 13:14:13 -0400 Subject: [PATCH] Change check for skipping the initial quickExpr RegExp check. Fixes #8984. --- src/core.js | 5 +++-- test/unit/core.js | 13 ++++++++++++- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/src/core.js b/src/core.js index 8d812e38..6ab06e15 100644 --- a/src/core.js +++ b/src/core.js @@ -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 ); } diff --git a/test/unit/core.js b/test/unit/core.js index f0bf24cd..7690756d 100644 --- a/test/unit/core.js +++ b/test/unit/core.js @@ -12,7 +12,7 @@ test("Basic requirements", function() { }); test("jQuery()", function() { - expect(25); + expect(29); // Basic constructor's behavior @@ -96,6 +96,17 @@ test("jQuery()", function() { // manually clean up detached elements elem.remove(); + + equals( jQuery("
").length, 1, "Make sure whitespace is trimmed." ); + equals( jQuery(" a
b ").length, 1, "Make sure whitespace and other characters are trimmed." ); + + var long = ""; + for ( var i = 0; i < 128; i++ ) { + long += "12345678"; + } + + equals( jQuery("
" + long + "
").length, 1, "Make sure whitespace is trimmed on long strings." ); + equals( jQuery(" a
" + long + "
b ").length, 1, "Make sure whitespace and other characters are trimmed on long strings." ); }); test("selector state", function() {