Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit09d988b

Browse files
authored
Selector: Make selector lists work withqSA again
jQuery 3.6.2 started using `CSS.supports( "selector(SELECTOR)" )` before using`querySelectorAll` on the selector. This was to solvegh-5098 - some selectors,like `:has()`, now had their parameters parsed in a forgiving way, meaningthat `:has(:fakepseudo)` no longer throws but just returns 0 results, breakingthat jQuery mechanism.A recent spec change made `CSS.supports( "selector(SELECTOR)" )` always usenon-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 updatebut our new mechanism is more future-proof anyway.However, the jQuery implementation has a bug - in`CSS.supports( "selector(SELECTOR)" )`, `SELECTOR` needs to bea `<complex-selector>` and not a `<complex-selector-list>`. Which means thatselector lists now skip `qSA` and go to the jQuery custom traversal:```jsCSS.supports("selector(div:valid, span)"); // falseCSS.supports("selector(div:valid)"); // trueCSS.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 singleselector 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-listFixesgh-5177Closesgh-5178Refw3c/csswg-drafts#7280
1 parent024d871 commit09d988b

File tree

4 files changed

+34
-7
lines changed

4 files changed

+34
-7
lines changed

‎src/selector.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -255,15 +255,20 @@ function find( selector, context, results, seed ) {
255255

256256
// `qSA` may not throw for unrecognized parts using forgiving parsing:
257257
// https://drafts.csswg.org/selectors/#forgiving-selector
258-
// like the `:has()` pseudo-class:
259-
// https://drafts.csswg.org/selectors/#relational
258+
// like the `:is()` pseudo-class:
259+
// https://drafts.csswg.org/selectors/#matches
260260
// `CSS.supports` is still expected to return `false` then:
261261
// https://drafts.csswg.org/css-conditional-4/#typedef-supports-selector-fn
262262
// https://drafts.csswg.org/css-conditional-4/#dfn-support-selector
263263
if(support.cssSupportsSelector&&
264264

265+
// `CSS.supports( "selector(...)" )` requires the argument to the
266+
// `selector` function to be a `<complex-selector>`, not
267+
// a `<complex-selector-list>` which our selector may be. Wrapping with
268+
// `:is` works around the issue and is supported by all browsers
269+
// we support except for IE which will fail the support test anyway.
265270
// eslint-disable-next-line no-undef
266-
!CSS.supports("selector("+newSelector+")")){
271+
!CSS.supports("selector(:is("+newSelector+"))")){
267272

268273
// Support: IE 11+
269274
// Throw to get to the same code path as an error directly in qSA.

‎src/selector/rbuggyQSA.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,8 @@ if ( !support.cssSupportsSelector ) {
2727
// `:has()` uses a forgiving selector list as an argument so our regular
2828
// `try-catch` mechanism fails to catch `:has()` with arguments not supported
2929
// natively like `:has(:contains("Foo"))`. Where supported & spec-compliant,
30-
// we now use `CSS.supports("selector(SELECTOR_TO_BE_TESTED)")` but outside
31-
// that, let's mark `:has` as buggy to always use jQuery traversal for
32-
// `:has()`.
30+
// we now use `CSS.supports("selector(:is(SELECTOR_TO_BE_TESTED))")`, but
31+
// outside that we mark `:has` as buggy.
3332
rbuggyQSA.push(":has");
3433
}
3534

‎src/selector/support.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
importsupportfrom"../var/support.js";
22

3+
// Support: IE 11+
4+
// IE doesn't support `CSS.supports( "selector(...)" )`; it will throw
5+
// in this support test.
36
try{
47
/* eslint-disable no-undef */
58

‎test/unit/selector.js

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -400,14 +400,34 @@ QUnit.test( "name", function( assert ) {
400400
});
401401

402402
QUnit.test("comma-separated",function(assert){
403-
assert.expect(4);
403+
assert.expect(10);
404404

405405
varfixture=jQuery("<div><h2><span></span></h2><div><p><span></span></p><p></p></div></div>");
406406

407407
assert.equal(fixture.find("h2, div p").filter("p").length,2,"has to find two <p>");
408408
assert.equal(fixture.find("h2, div p").filter("h2").length,1,"has to find one <h2>");
409409
assert.equal(fixture.find("h2 , div p").filter("p").length,2,"has to find two <p>");
410410
assert.equal(fixture.find("h2 , div p").filter("h2").length,1,"has to find one <h2>");
411+
assert.equal(fixture.find("h2 ,div p").filter("p").length,2,"has to find two <p>");
412+
assert.equal(fixture.find("h2 ,div p").filter("h2").length,1,"has to find one <h2>");
413+
assert.equal(fixture.find("h2,div p").filter("p").length,2,"has to find two <p>");
414+
assert.equal(fixture.find("h2,div p").filter("h2").length,1,"has to find one <h2>");
415+
assert.equal(fixture.find("h2\t,\rdiv p").filter("p").length,2,"has to find two <p>");
416+
assert.equal(fixture.find("h2\t,\rdiv p").filter("h2").length,1,"has to find one <h2>");
417+
});
418+
419+
QUnit.test("comma-separated, only supported natively (gh-5177)",function(assert){
420+
assert.expect(5);
421+
422+
varfixture=jQuery("<div><input/><span></span></div>");
423+
424+
fixture.appendTo("#qunit-fixture");
425+
426+
assert.equal(fixture.find("input:valid, span").length,2,"has to find two elements");
427+
assert.equal(fixture.find("input:valid , span").length,2,"has to find two elements");
428+
assert.equal(fixture.find("input:valid ,span").length,2,"has to find two elements");
429+
assert.equal(fixture.find("input:valid,span").length,2,"has to find two elements");
430+
assert.equal(fixture.find("input:valid\t,\rspan").length,2,"has to find two elements");
411431
});
412432

413433
QUnit.test("child and adjacent",function(assert){

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp