aboutsummaryrefslogtreecommitdiffstats
path: root/test/unit/selector.js
diff options
context:
space:
mode:
authorMichał Gołębiowski-Owczarek <m.goleb@gmail.com>2022-12-19 18:43:30 +0100
committerGitHub <noreply@github.com>2022-12-19 18:43:30 +0100
commit09d988b774e7ff4acfb69c0cde2dab373559aaca (patch)
tree99e41463a57ab4a82c3198922f1df96ca0a33091 /test/unit/selector.js
parent024d87195ac46690023e2b0b308d4406a8a5a27e (diff)
downloadjquery-09d988b774e7ff4acfb69c0cde2dab373559aaca.tar.gz
jquery-09d988b774e7ff4acfb69c0cde2dab373559aaca.zip
Selector: Make selector lists work with `qSA` again
jQuery 3.6.2 started using `CSS.supports( "selector(SELECTOR)" )` before using `querySelectorAll` on the selector. This was to solve gh-5098 - some selectors, like `:has()`, now had their parameters parsed in a forgiving way, meaning that `:has(:fakepseudo)` no longer throws but just returns 0 results, breaking that jQuery mechanism. A recent spec change made `CSS.supports( "selector(SELECTOR)" )` always use non-forgiving parsing, allowing us to use this API for what we've used `try-catch` before. To solve the issue on the spec side for older jQuery versions, `:has()` parameters are no longer using forgiving parsing in the latest spec update but our new mechanism is more future-proof anyway. However, the jQuery implementation has a bug - in `CSS.supports( "selector(SELECTOR)" )`, `SELECTOR` needs to be a `<complex-selector>` and not a `<complex-selector-list>`. Which means that selector lists now skip `qSA` and go to the jQuery custom traversal: ```js CSS.supports("selector(div:valid, span)"); // false CSS.supports("selector(div:valid)"); // true CSS.supports("selector(span)"); // true ``` To solve this, this commit wraps the selector list passed to `CSS.supports( "selector(:is(SELECTOR))" )` with `:is`, making it a single selector again. See: * https://w3c.github.io/csswg-drafts/css-conditional-4/#at-supports-ext * https://w3c.github.io/csswg-drafts/selectors-4/#typedef-complex-selector * https://w3c.github.io/csswg-drafts/selectors-4/#typedef-complex-selector-list Fixes gh-5177 Closes gh-5178 Ref w3c/csswg-drafts#7280
Diffstat (limited to 'test/unit/selector.js')
-rw-r--r--test/unit/selector.js22
1 files changed, 21 insertions, 1 deletions
diff --git a/test/unit/selector.js b/test/unit/selector.js
index 0057fe57a..d177ab997 100644
--- a/test/unit/selector.js
+++ b/test/unit/selector.js
@@ -400,7 +400,7 @@ QUnit.test( "name", function( assert ) {
} );
QUnit.test( "comma-separated", function( assert ) {
- assert.expect( 4 );
+ assert.expect( 10 );
var fixture = jQuery( "<div><h2><span></span></h2><div><p><span></span></p><p></p></div></div>" );
@@ -408,6 +408,26 @@ QUnit.test( "comma-separated", function( assert ) {
assert.equal( fixture.find( "h2, div p" ).filter( "h2" ).length, 1, "has to find one <h2>" );
assert.equal( fixture.find( "h2 , div p" ).filter( "p" ).length, 2, "has to find two <p>" );
assert.equal( fixture.find( "h2 , div p" ).filter( "h2" ).length, 1, "has to find one <h2>" );
+ assert.equal( fixture.find( "h2 ,div p" ).filter( "p" ).length, 2, "has to find two <p>" );
+ assert.equal( fixture.find( "h2 ,div p" ).filter( "h2" ).length, 1, "has to find one <h2>" );
+ assert.equal( fixture.find( "h2,div p" ).filter( "p" ).length, 2, "has to find two <p>" );
+ assert.equal( fixture.find( "h2,div p" ).filter( "h2" ).length, 1, "has to find one <h2>" );
+ assert.equal( fixture.find( "h2\t,\rdiv p" ).filter( "p" ).length, 2, "has to find two <p>" );
+ assert.equal( fixture.find( "h2\t,\rdiv p" ).filter( "h2" ).length, 1, "has to find one <h2>" );
+} );
+
+QUnit.test( "comma-separated, only supported natively (gh-5177)", function( assert ) {
+ assert.expect( 5 );
+
+ var fixture = jQuery( "<div><input/><span></span></div>" );
+
+ fixture.appendTo( "#qunit-fixture" );
+
+ assert.equal( fixture.find( "input:valid, span" ).length, 2, "has to find two elements" );
+ assert.equal( fixture.find( "input:valid , span" ).length, 2, "has to find two elements" );
+ assert.equal( fixture.find( "input:valid ,span" ).length, 2, "has to find two elements" );
+ assert.equal( fixture.find( "input:valid,span" ).length, 2, "has to find two elements" );
+ assert.equal( fixture.find( "input:valid\t,\rspan" ).length, 2, "has to find two elements" );
} );
QUnit.test( "child and adjacent", function( assert ) {