Skip to content

Commit 5586fed

Browse files
committed
Fixed a bug with certain + selectors failing (Fixes jQuery bug jquery#4023). Also tweaked the + and > functions a little bit.
1 parent f0189d6 commit 5586fed

File tree

2 files changed

+22
-10
lines changed

2 files changed

+22
-10
lines changed

src/selector.js

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -261,23 +261,32 @@ var Expr = Sizzle.selectors = {
261261
},
262262
relative: {
263263
"+": function(checkSet, part, isXML){
264-
var isPartStr = typeof part === "string",
264+
var isPartStr = typeof part === "string",
265265
isTag = isPartStr && !/\W/.test(part),
266266
isPartStrNotTag = isPartStr && !isTag;
267-
if ( isTag && !isXML ) part = part.toUpperCase();
267+
268+
if ( isTag && !isXML ) {
269+
part = part.toUpperCase();
270+
}
271+
268272
for ( var i = 0, l = checkSet.length, elem; i < l; i++ ) {
269-
if ( elem = checkSet[i] ) {
270-
while ( (elem = elem.previousSibling) && elem.nodeType !== 1 ) {};
273+
if ( (elem = checkSet[i]) ) {
274+
while ( (elem = elem.previousSibling) && elem.nodeType !== 1 ) {}
275+
271276
checkSet[i] = isPartStrNotTag || elem && elem.nodeName === part ?
272-
elem : elem === part;
277+
elem || false :
278+
elem === part;
273279
}
274280
}
275-
if (isPartStrNotTag) {
281+
282+
if ( isPartStrNotTag ) {
276283
Sizzle.filter( part, checkSet, true );
277284
}
278285
},
279286
">": function(checkSet, part, isXML){
280-
if ( typeof part === "string" && !/\W/.test(part) ) {
287+
var isPartStr = typeof part === "string";
288+
289+
if ( isPartStr && !/\W/.test(part) ) {
281290
part = isXML ? part : part.toUpperCase();
282291

283292
for ( var i = 0, l = checkSet.length; i < l; i++ ) {
@@ -291,13 +300,13 @@ var Expr = Sizzle.selectors = {
291300
for ( var i = 0, l = checkSet.length; i < l; i++ ) {
292301
var elem = checkSet[i];
293302
if ( elem ) {
294-
checkSet[i] = typeof part === "string" ?
303+
checkSet[i] = isPartStr ?
295304
elem.parentNode :
296305
elem.parentNode === part;
297306
}
298307
}
299308

300-
if ( typeof part === "string" ) {
309+
if ( isPartStr ) {
301310
Sizzle.filter( part, checkSet, true );
302311
}
303312
}

test/unit/selector.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ test("multiple", function() {
180180
});
181181

182182
test("child and adjacent", function() {
183-
expect(45);
183+
expect(48);
184184
t( "Child", "p > a", ["simon1","google","groups","mark","yahoo","simon"] );
185185
t( "Child", "p> a", ["simon1","google","groups","mark","yahoo","simon"] );
186186
t( "Child", "p >a", ["simon1","google","groups","mark","yahoo","simon"] );
@@ -193,6 +193,9 @@ test("child and adjacent", function() {
193193
t( "Adjacent", "a+ a", ["groups"] );
194194
t( "Adjacent", "a+a", ["groups"] );
195195
t( "Adjacent", "p + p", ["ap","en","sap"] );
196+
t( "Adjacent", "p#firstp + p", ["ap"] );
197+
t( "Adjacent", "p[lang=en] + p", ["sap"] );
198+
t( "Adjacent", "a.GROUPS + code + a", ["mark"] );
196199
t( "Comma, Child, and Adjacent", "a + a, code > a", ["groups","anchor1","anchor2"] );
197200

198201
t( "Verify deep class selector", "div.blah > p > a", [] );

0 commit comments

Comments
 (0)