Skip to content
Permalink
Browse files

Fixed a bug with certain + selectors failing (Fixes jQuery bug #4023)…

…. Also tweaked the + and > functions a little bit.
  • Loading branch information
jeresig committed Feb 16, 2009
1 parent f0189d6 commit 5586fedf2932dc17b303c860d9f0a7604223f865
Showing with 22 additions and 10 deletions.
  1. +18 −9 src/selector.js
  2. +4 −1 test/unit/selector.js
@@ -261,23 +261,32 @@ var Expr = Sizzle.selectors = {
},
relative: {
"+": function(checkSet, part, isXML){
var isPartStr = typeof part === "string",
var isPartStr = typeof part === "string",
isTag = isPartStr && !/\W/.test(part),
isPartStrNotTag = isPartStr && !isTag;
if ( isTag && !isXML ) part = part.toUpperCase();

if ( isTag && !isXML ) {
part = part.toUpperCase();
}

for ( var i = 0, l = checkSet.length, elem; i < l; i++ ) {
if ( elem = checkSet[i] ) {
while ( (elem = elem.previousSibling) && elem.nodeType !== 1 ) {};
if ( (elem = checkSet[i]) ) {
while ( (elem = elem.previousSibling) && elem.nodeType !== 1 ) {}

checkSet[i] = isPartStrNotTag || elem && elem.nodeName === part ?
elem : elem === part;
elem || false :
elem === part;
}
}
if (isPartStrNotTag) {

if ( isPartStrNotTag ) {
Sizzle.filter( part, checkSet, true );
}
},
">": function(checkSet, part, isXML){
if ( typeof part === "string" && !/\W/.test(part) ) {
var isPartStr = typeof part === "string";

if ( isPartStr && !/\W/.test(part) ) {
part = isXML ? part : part.toUpperCase();

for ( var i = 0, l = checkSet.length; i < l; i++ ) {
@@ -291,13 +300,13 @@ var Expr = Sizzle.selectors = {
for ( var i = 0, l = checkSet.length; i < l; i++ ) {
var elem = checkSet[i];
if ( elem ) {
checkSet[i] = typeof part === "string" ?
checkSet[i] = isPartStr ?
elem.parentNode :
elem.parentNode === part;
}
}

if ( typeof part === "string" ) {
if ( isPartStr ) {
Sizzle.filter( part, checkSet, true );
}
}
@@ -180,7 +180,7 @@ test("multiple", function() {
});

test("child and adjacent", function() {
expect(45);
expect(48);
t( "Child", "p > a", ["simon1","google","groups","mark","yahoo","simon"] );
t( "Child", "p> a", ["simon1","google","groups","mark","yahoo","simon"] );
t( "Child", "p >a", ["simon1","google","groups","mark","yahoo","simon"] );
@@ -193,6 +193,9 @@ test("child and adjacent", function() {
t( "Adjacent", "a+ a", ["groups"] );
t( "Adjacent", "a+a", ["groups"] );
t( "Adjacent", "p + p", ["ap","en","sap"] );
t( "Adjacent", "p#firstp + p", ["ap"] );
t( "Adjacent", "p[lang=en] + p", ["sap"] );
t( "Adjacent", "a.GROUPS + code + a", ["mark"] );
t( "Comma, Child, and Adjacent", "a + a, code > a", ["groups","anchor1","anchor2"] );

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

0 comments on commit 5586fed

Please sign in to comment.
You can’t perform that action at this time.