Skip to content

Selector: Make selector lists work with qSA again #491

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Dec 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions src/sizzle.js
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ function Sizzle( selector, context, results, seed ) {
if ( support.cssSupportsSelector &&

// eslint-disable-next-line no-undef
!CSS.supports( "selector(" + newSelector + ")" ) ) {
!CSS.supports( "selector(:is(" + newSelector + "))" ) ) {

// Support: IE 11+
// Throw to get to the same code path as an error directly in qSA.
Expand Down Expand Up @@ -969,9 +969,8 @@ setDocument = Sizzle.setDocument = function( node ) {
// `:has()` uses a forgiving selector list as an argument so our regular
// `try-catch` mechanism fails to catch `:has()` with arguments not supported
// natively like `:has(:contains("Foo"))`. Where supported & spec-compliant,
// we now use `CSS.supports("selector(SELECTOR_TO_BE_TESTED)")` but outside
// that, let's mark `:has` as buggy to always use jQuery traversal for
// `:has()`.
// we now use `CSS.supports("selector(:is(SELECTOR_TO_BE_TESTED))")`, but
// outside that we mark `:has` as buggy.
rbuggyQSA.push( ":has" );
}

Expand Down
31 changes: 31 additions & 0 deletions test/unit/selector.js
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,37 @@ QUnit.test( "multiple", function( assert ) {
[ "h2", "firstp", "ap", "sndp", "en", "sap", "first" ] );
} );

( function() {
var supportsValidPseudo;
try {
supportsValidPseudo = document.querySelectorAll( "input:valid" ) &&

// Support: Firefox 3.6 only
// Firefox 3.6 doesn't support the `:valid` pseudo-class, but it also
// doesn't throw when a `qSA` call includes it.
!/firefox\/3\.6/i.test( navigator.userAgent );
} catch ( e ) {
supportsValidPseudo = false;
}

if ( supportsValidPseudo ) {
QUnit.test( "multiple, only supported natively (jquery/jquery#5177)", function( assert ) {
assert.expect( 4 );

jQuery( "#qunit-fixture" ).prepend( "<h2 id='h2'/>" );

t( "Comma Support", "#qunit-fixture #search:valid, #qunit-fixture p",
[ "firstp", "ap", "sndp", "en", "sap", "first", "search" ] );
t( "Comma Support", "#qunit-fixture #search:valid , #qunit-fixture p",
[ "firstp", "ap", "sndp", "en", "sap", "first", "search" ] );
t( "Comma Support", "#qunit-fixture #search:valid,#qunit-fixture p",
[ "firstp", "ap", "sndp", "en", "sap", "first", "search" ] );
t( "Comma Support", "#qunit-fixture #search:valid\t,\r#qunit-fixture p\n",
[ "firstp", "ap", "sndp", "en", "sap", "first", "search" ] );
} );
}
} )();

QUnit.test( "child and adjacent", function( assert ) {
assert.expect( 43 );

Expand Down