diff options
author | John Resig <jeresig@gmail.com> | 2011-05-02 13:14:13 -0400 |
---|---|---|
committer | John Resig <jeresig@gmail.com> | 2011-05-02 13:14:13 -0400 |
commit | 86aa764f0b7b659fbd8eec9333d22c3a79bdfcd5 (patch) | |
tree | 8aa650ad330250e7cb6a7bd2176da14188626d63 | |
parent | f1392d82089323ec9ef97b33909b960cc16c25b6 (diff) | |
download | jquery-86aa764f0b7b659fbd8eec9333d22c3a79bdfcd5.tar.gz jquery-86aa764f0b7b659fbd8eec9333d22c3a79bdfcd5.zip |
Change check for skipping the initial quickExpr RegExp check. Fixes #8984.
-rw-r--r-- | src/core.js | 5 | ||||
-rw-r--r-- | test/unit/core.js | 13 |
2 files changed, 15 insertions, 3 deletions
diff --git a/src/core.js b/src/core.js index 8d812e384..6ab06e15b 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 f0bf24cd5..7690756d9 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(" <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() { |