aboutsummaryrefslogtreecommitdiffstats
path: root/src/traversing.js
diff options
context:
space:
mode:
authorRichard Gibson <richard.gibson@gmail.com>2016-01-12 00:56:29 -0500
committerTimmy Willison <timmywillisn@gmail.com>2016-01-13 13:37:11 -0500
commita268f5225cad9ab380494e61a10105cc9eb107e7 (patch)
tree24ce40442fd461d8b314b0ba9e2ae9f72f95184c /src/traversing.js
parent0e2f8f9effd2c95647be534bf9055e099aad7cfd (diff)
downloadjquery-a268f5225cad9ab380494e61a10105cc9eb107e7.tar.gz
jquery-a268f5225cad9ab380494e61a10105cc9eb107e7.zip
Traversing: Never let .closest() match positional selectors
Fixes gh-2796 Close gh-2818
Diffstat (limited to 'src/traversing.js')
-rw-r--r--src/traversing.js27
1 files changed, 14 insertions, 13 deletions
diff --git a/src/traversing.js b/src/traversing.js
index 0d4c1c4c3..8525c0a5d 100644
--- a/src/traversing.js
+++ b/src/traversing.js
@@ -39,23 +39,24 @@ jQuery.fn.extend( {
i = 0,
l = this.length,
matched = [],
- pos = rneedsContext.test( selectors ) || typeof selectors !== "string" ?
- jQuery( selectors, context || this.context ) :
- 0;
+ targets = typeof selectors !== "string" && jQuery( selectors );
- for ( ; i < l; i++ ) {
- for ( cur = this[ i ]; cur && cur !== context; cur = cur.parentNode ) {
+ // Positional selectors never match, since there's no _selection_ context
+ if ( !rneedsContext.test( selectors ) ) {
+ for ( ; i < l; i++ ) {
+ for ( cur = this[ i ]; cur && cur !== context; cur = cur.parentNode ) {
- // Always skip document fragments
- if ( cur.nodeType < 11 && ( pos ?
- pos.index( cur ) > -1 :
+ // Always skip document fragments
+ if ( cur.nodeType < 11 && ( targets ?
+ targets.index( cur ) > -1 :
- // Don't pass non-elements to Sizzle
- cur.nodeType === 1 &&
- jQuery.find.matchesSelector( cur, selectors ) ) ) {
+ // Don't pass non-elements to Sizzle
+ cur.nodeType === 1 &&
+ jQuery.find.matchesSelector( cur, selectors ) ) ) {
- matched.push( cur );
- break;
+ matched.push( cur );
+ break;
+ }
}
}
}