Skip to content

Commit 2082770

Browse files
committed
Added fixes for two different :not() bugs. One with p:not(p.foo) failing and another with a weird combination of multiple selectors and filters. Fixes jQuery bug jquery#4101.
1 parent f9a7cfa commit 2082770

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

src/selector.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -223,8 +223,6 @@ Sizzle.filter = function(expr, set, inplace, not){
223223
}
224224
}
225225

226-
expr = expr.replace(/\s*,\s*/, "");
227-
228226
// Improper expression
229227
if ( expr == old ) {
230228
if ( anyFound == null ) {
@@ -399,7 +397,7 @@ var Expr = Sizzle.selectors = {
399397
PSEUDO: function(match, curLoop, inplace, result, not){
400398
if ( match[1] === "not" ) {
401399
// If we're dealing with a complex expression, or a simple one
402-
if ( match[3].match(chunker).length > 1 ) {
400+
if ( match[3].match(chunker).length > 1 || /^\w/.test(match[3]) ) {
403401
match[3] = Sizzle(match[3], null, null, curLoop);
404402
} else {
405403
var ret = Sizzle.filter(match[3], curLoop, inplace, true ^ not);

test/unit/selector.js

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,7 @@ test("attributes", function() {
296296
});
297297

298298
test("pseudo (:) selectors", function() {
299-
expect(53);
299+
expect(67);
300300
t( "First Child", "p:first-child", ["firstp","sndp"] );
301301
t( "Last Child", "p:last-child", ["sap"] );
302302
t( "Only Child", "a:only-child", ["simon1","anchor1","yahoo","anchor2","liveLink1","liveLink2"] );
@@ -316,6 +316,22 @@ test("pseudo (:) selectors", function() {
316316
t( "Not - multiple", "#form option:not(:contains('Nothing'),#option1b,:selected)", ["option1c", "option1d", "option2b", "option2c", "option3d", "option3e"] );
317317
//t( "Not - complex", "#form option:not([id^='opt']:nth-child(-n+3))", [ "option1a", "option1d", "option2d", "option3d", "option3e"] );
318318
t( "Not - recursive", "#form option:not(:not(:selected))[id^='option3']", [ "option3b", "option3c"] );
319+
320+
t( ":not() failing interior", "p:not(.foo)", ["firstp","ap","sndp","en","sap","first"] );
321+
t( ":not() failing interior", "p:not(div.foo)", ["firstp","ap","sndp","en","sap","first"] );
322+
t( ":not() failing interior", "p:not(p.foo)", ["firstp","ap","sndp","en","sap","first"] );
323+
t( ":not() failing interior", "p:not(#blargh)", ["firstp","ap","sndp","en","sap","first"] );
324+
t( ":not() failing interior", "p:not(div#blargh)", ["firstp","ap","sndp","en","sap","first"] );
325+
t( ":not() failing interior", "p:not(p#blargh)", ["firstp","ap","sndp","en","sap","first"] );
326+
327+
t( ":not Multiple", "p:not(a)", ["firstp","ap","sndp","en","sap","first"] );
328+
t( ":not Multiple", "p:not(a, b)", ["firstp","ap","sndp","en","sap","first"] );
329+
t( ":not Multiple", "p:not(a, b, div)", ["firstp","ap","sndp","en","sap","first"] );
330+
t( ":not Multiple", "p:not(p)", [] );
331+
t( ":not Multiple", "p:not(a,p)", [] );
332+
t( ":not Multiple", "p:not(p,a)", [] );
333+
t( ":not Multiple", "p:not(a,p,b)", [] );
334+
t( ":not Multiple", ":input:not(:image,:input,:submit)", [] );
319335

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

0 commit comments

Comments
 (0)