Skip to content

Commit

Permalink
Added fixes for two different :not() bugs. One with p:not(p.foo) fail…
Browse files Browse the repository at this point in the history
…ing and another with a weird combination of multiple selectors and filters. Fixes jQuery bug #4101.
  • Loading branch information
jeresig committed Feb 15, 2009
1 parent f9a7cfa commit 2082770
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
4 changes: 1 addition & 3 deletions src/selector.js
Expand Up @@ -223,8 +223,6 @@ Sizzle.filter = function(expr, set, inplace, not){
}
}

expr = expr.replace(/\s*,\s*/, "");

// Improper expression
if ( expr == old ) {
if ( anyFound == null ) {
Expand Down Expand Up @@ -399,7 +397,7 @@ var Expr = Sizzle.selectors = {
PSEUDO: function(match, curLoop, inplace, result, not){
if ( match[1] === "not" ) {
// If we're dealing with a complex expression, or a simple one
if ( match[3].match(chunker).length > 1 ) {
if ( match[3].match(chunker).length > 1 || /^\w/.test(match[3]) ) {
match[3] = Sizzle(match[3], null, null, curLoop);
} else {
var ret = Sizzle.filter(match[3], curLoop, inplace, true ^ not);
Expand Down
18 changes: 17 additions & 1 deletion test/unit/selector.js
Expand Up @@ -296,7 +296,7 @@ test("attributes", function() {
});

test("pseudo (:) selectors", function() {
expect(53);
expect(67);
t( "First Child", "p:first-child", ["firstp","sndp"] );
t( "Last Child", "p:last-child", ["sap"] );
t( "Only Child", "a:only-child", ["simon1","anchor1","yahoo","anchor2","liveLink1","liveLink2"] );
Expand All @@ -316,6 +316,22 @@ test("pseudo (:) selectors", function() {
t( "Not - multiple", "#form option:not(:contains('Nothing'),#option1b,:selected)", ["option1c", "option1d", "option2b", "option2c", "option3d", "option3e"] );
//t( "Not - complex", "#form option:not([id^='opt']:nth-child(-n+3))", [ "option1a", "option1d", "option2d", "option3d", "option3e"] );
t( "Not - recursive", "#form option:not(:not(:selected))[id^='option3']", [ "option3b", "option3c"] );

t( ":not() failing interior", "p:not(.foo)", ["firstp","ap","sndp","en","sap","first"] );
t( ":not() failing interior", "p:not(div.foo)", ["firstp","ap","sndp","en","sap","first"] );
t( ":not() failing interior", "p:not(p.foo)", ["firstp","ap","sndp","en","sap","first"] );
t( ":not() failing interior", "p:not(#blargh)", ["firstp","ap","sndp","en","sap","first"] );
t( ":not() failing interior", "p:not(div#blargh)", ["firstp","ap","sndp","en","sap","first"] );
t( ":not() failing interior", "p:not(p#blargh)", ["firstp","ap","sndp","en","sap","first"] );

t( ":not Multiple", "p:not(a)", ["firstp","ap","sndp","en","sap","first"] );
t( ":not Multiple", "p:not(a, b)", ["firstp","ap","sndp","en","sap","first"] );
t( ":not Multiple", "p:not(a, b, div)", ["firstp","ap","sndp","en","sap","first"] );
t( ":not Multiple", "p:not(p)", [] );
t( ":not Multiple", "p:not(a,p)", [] );
t( ":not Multiple", "p:not(p,a)", [] );
t( ":not Multiple", "p:not(a,p,b)", [] );
t( ":not Multiple", ":input:not(:image,:input,:submit)", [] );

t( "nth Element", "p:nth(1)", ["ap"] );
t( "First Element", "p:first", ["firstp"] );
Expand Down

0 comments on commit 2082770

Please sign in to comment.