diff --git a/sizzle.js b/sizzle.js index ac01c043..a874b3d6 100644 --- a/sizzle.js +++ b/sizzle.js @@ -1196,7 +1196,8 @@ function handlePOSGroup( selector, posfilter, argument, contexts, seed, not ) { } if ( selector || !(results = seed) ) { - multipleContexts( selector || "*", contexts, (results = []), seed ); + // Make sure the selector is not a bunch of white spaces. Fixes jQuery #12474 + multipleContexts( selector.replace( rtrim, "$1" ) || "*", contexts, (results = []), seed ); } return results.length > 0 ? fn( results, argument, not ) : []; diff --git a/test/unit/selector.js b/test/unit/selector.js index cd2b1178..7554da66 100644 --- a/test/unit/selector.js +++ b/test/unit/selector.js @@ -711,13 +711,21 @@ test("pseudo - :not", function() { }); test("pseudo - position", function() { - expect( 32 ); + expect( 34 ); t( "First element", "div:first", ["qunit-testrunner-toolbar"] ); t( "First element(case-insensitive)", "div:fiRst", ["qunit-testrunner-toolbar"] ); t( "nth Element", "#qunit-fixture p:nth(1)", ["ap"] ); t( "First Element", "#qunit-fixture p:first", ["firstp"] ); t( "Last Element", "p:last", ["first"] ); + + var ret = [], foo = document.getElementById("foo"); + Sizzle( ":first", foo, ret ); + Sizzle( ":last", foo, ret ); + + equal( ret[0].id, "sndp", "plain :first working on specific context" ); + equal( ret[1].id, "simon", "plain :last working on specific context" ); + t( "Even Elements", "#qunit-fixture p:even", ["firstp","sndp","sap"] ); t( "Odd Elements", "#qunit-fixture p:odd", ["ap","en","first"] ); t( "Position Equals", "#qunit-fixture p:eq(1)", ["ap"] );