Permalink
Browse files

Selector: Prevent seeded invocations from cutting off the qSA path

Fixes gh-393
Closes gh-396
1 parent 0a60995 commit eabce51ea7360c4507da2eeaec2633378de4ec8d @gibson042 gibson042 committed Nov 21, 2016
Showing with 18 additions and 10 deletions.
  1. +8 −4 dist/sizzle.js
  2. +2 −2 dist/sizzle.min.js
  3. +1 −1 dist/sizzle.min.map
  4. +7 −3 src/sizzle.js
View
@@ -6,7 +6,7 @@
* Released under the MIT license
* https://js.foundation/
*
- * Date: 2016-11-20
+ * Date: 2016-12-02
*/
(function( window ) {
@@ -40,6 +40,7 @@ var i,
classCache = createCache(),
tokenCache = createCache(),
compilerCache = createCache(),
+ nonnativeSelectorCache = createCache(),
sortOrder = function( a, b ) {
if ( a === b ) {
hasDuplicate = true;
@@ -292,7 +293,7 @@ function Sizzle( selector, context, results, seed ) {
// Take advantage of querySelectorAll
if ( support.qsa &&
- !compilerCache[ selector + " " ] &&
+ !nonnativeSelectorCache[ selector + " " ] &&
(!rbuggyQSA || !rbuggyQSA.test( selector )) ) {
if ( nodeType !== 1 ) {
@@ -332,6 +333,7 @@ function Sizzle( selector, context, results, seed ) {
);
return results;
} catch ( qsaError ) {
+ nonnativeSelectorCache( selector );
} finally {
if ( nid === expando ) {
context.removeAttribute( "id" );
@@ -985,7 +987,7 @@ Sizzle.matchesSelector = function( elem, expr ) {
expr = expr.replace( rattributeQuotes, "='$1']" );
if ( support.matchesSelector && documentIsHTML &&
- !compilerCache[ expr + " " ] &&
+ !nonnativeSelectorCache[ expr + " " ] &&
( !rbuggyMatches || !rbuggyMatches.test( expr ) ) &&
( !rbuggyQSA || !rbuggyQSA.test( expr ) ) ) {
@@ -999,7 +1001,9 @@ Sizzle.matchesSelector = function( elem, expr ) {
elem.document && elem.document.nodeType !== 11 ) {
return ret;
}
- } catch (e) {}
+ } catch (e) {
+ nonnativeSelectorCache( expr );
+ }
}
return Sizzle( expr, document, null, [ elem ] ).length > 0;
Oops, something went wrong.

0 comments on commit eabce51

Please sign in to comment.