aboutsummaryrefslogtreecommitdiffstats
path: root/test/unit/selector.js
diff options
context:
space:
mode:
authorMichał Gołębiowski-Owczarek <m.goleb@gmail.com>2022-09-19 21:56:02 +0300
committerGitHub <noreply@github.com>2022-09-19 20:56:02 +0200
commitd153c375e67f2c2dba82c2fb079c36b8d795e66a (patch)
tree68849b687ce4dd7ab9a9bf8db648e06d3eac3259 /test/unit/selector.js
parent78321f078ce04ce78aeade8e2860ac41d05fae54 (diff)
downloadjquery-d153c375e67f2c2dba82c2fb079c36b8d795e66a.tar.gz
jquery-d153c375e67f2c2dba82c2fb079c36b8d795e66a.zip
Selector: Use jQuery `:has` if `CSS.supports(selector(...))` non-compliant
jQuery has followed the following logic for selector handling for ages: 1. Modify the selector to adhere to scoping rules jQuery mandates. 2. Try `qSA` on the modified selector. If it succeeds, use the results. 3. If `qSA` threw an error, run the jQuery custom traversal instead. It worked fine so far but now CSS has a concept of forgiving selector lists that some selectors like `:is()` & `:has()` use. That means providing unrecognized selectors as parameters to `:is()` & `:has()` no longer throws an error, it will just return no results. That made browsers with native `:has()` support break selectors using jQuery extensions inside, e.g. `:has(:contains("Item"))`. Detecting support for selectors can also be done via: ```js CSS.supports( "selector(SELECTOR_TO_BE_TESTED)" ) ``` which returns a boolean. There was a recent spec change requiring this API to always use non-forgiving parsing: https://github.com/w3c/csswg-drafts/issues/7280#issuecomment-1143852187 However, no browsers have implemented this change so far. To solve this, two changes are being made: 1. In browsers supports the new spec change to `CSS.supports( "selector()" )`, use it before trying `qSA`. 2. Otherwise, add `:has` to the buggy selectors list. Fixes gh-5098 Closes gh-5107 Ref w3c/csswg-drafts#7676
Diffstat (limited to 'test/unit/selector.js')
-rw-r--r--test/unit/selector.js12
1 files changed, 11 insertions, 1 deletions
diff --git a/test/unit/selector.js b/test/unit/selector.js
index 2b0c251cf..b1529175b 100644
--- a/test/unit/selector.js
+++ b/test/unit/selector.js
@@ -931,13 +931,23 @@ QUnit.test( "pseudo - nth-last-of-type", function( assert ) {
} );
QUnit[ QUnit.jQuerySelectors ? "test" : "skip" ]( "pseudo - has", function( assert ) {
- assert.expect( 3 );
+ assert.expect( 4 );
assert.t( "Basic test", "p:has(a)", [ "firstp", "ap", "en", "sap" ] );
assert.t( "Basic test (irrelevant whitespace)", "p:has( a )", [ "firstp", "ap", "en", "sap" ] );
assert.t( "Nested with overlapping candidates",
"#qunit-fixture div:has(div:has(div:not([id])))",
[ "moretests", "t2037", "fx-test-group", "fx-queue" ] );
+
+ // Support: Safari 15.4+, Chrome 105+
+ // `qSA` in Safari/Chrome throws for `:has()` with only unsupported arguments
+ // but if you add a supported arg to the list, it will run and just potentially
+ // return no results. Make sure this is accounted for. (gh-5098)
+ // Note: Chrome 105 has this behavior only in 105.0.5195.125 or newer;
+ // initially it shipped with a fully forgiving parsing in `:has()`.
+ assert.t( "Nested with list arguments",
+ "#qunit-fixture div:has(faketag, div:has(faketag, div:not([id])))",
+ [ "moretests", "t2037", "fx-test-group", "fx-queue" ] );
} );
QUnit[ QUnit.jQuerySelectors ? "test" : "skip" ]( "pseudo - contains", function( assert ) {