Skip to content

Commit

Permalink
Fixed a bug with certain + selectors failing (Fixes jQuery bug jquery…
Browse files Browse the repository at this point in the history
…#4023). Also tweaked the + and > functions a little bit.
  • Loading branch information
jeresig committed Feb 16, 2009
1 parent f0189d6 commit 5586fed
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 10 deletions.
27 changes: 18 additions & 9 deletions src/selector.js
Original file line number Diff line number Diff line change
Expand Up @@ -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++ ) {
Expand All @@ -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 );
}
}
Expand Down
5 changes: 4 additions & 1 deletion test/unit/selector.js
Original file line number Diff line number Diff line change
Expand Up @@ -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"] );
Expand All @@ -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", [] );
Expand Down

0 comments on commit 5586fed

Please sign in to comment.