8000 Colon-Prefixed Classes Break :scope Selectors in querySelector/querySelectorAll · Issue #3692 · jsdom/jsdom · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Colon-Prefixed Classes Break :scope Selectors in querySelector/querySelectorAll #3692

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

Closed
cooperwalbrun opened this issue Mar 8, 2024 · 0 comments · Fixed by #3854
Closed

Colon-Prefixed Classes Break :scope Selectors in querySelector/querySelectorAll #3692

8000 cooperwalbrun opened this issue Mar 8, 2024 · 0 comments · Fixed by #3854
Labels
has to-upstream test This bug has a failing to-upstream web platform test waiting to be fixed selectors CSS Selectors support

Comments

@cooperwalbrun
Copy link

Basic info:

  • Node.js version: 18.15.0
  • jsdom version: 24.0.0

Minimal reproduction case

const jsdom = require('jsdom');
const { JSDOM } = jsdom;
const string =  `<div class="sm:block"><span></span></div>`;

const html = new JSDOM(string);
const htmldoc = html.window.document;

const div = htmldoc.querySelector('div');
const span = div.querySelectorAll(':scope > span'); // Also breaks if using querySelector

How does similar code behave in browsers?

This code works fine in web browsers.

Other Details

jsdom appears to substitute the :scope selector with whatever part of the X:-prefixed class name comes after X.

If I change the class="sm:block" to e.g. class="anything-not-colon-prefixed sm:block", it works. It seems the problem only occurs when the only classes defined on the element are those with a : prefix.

Stack Trace

~/jsdom-issue/node_modules/nwsapi/src/nwsapi.js:559
        throw err;
        ^
DOMException [SyntaxError]: unknown pseudo-class selector ':block>*'
    at emit (~/jsdom-issue/node_modules/nwsapi/src/nwsapi.js:557:17)
    at compileSelector (~/jsdom-issue/node_modules/nwsapi/src/nwsapi.js:1273:17)
    at compile (~/jsdom-issue/node_modules/nwsapi/src/nwsapi.js:745:16)
    at collect (~/jsdom-issue/node_modules/nwsapi/src/nwsapi.js:1539:22)
    at Object._querySelectorAll [as select] (~/jsdom-issue/node_modules/nwsapi/src/nwsapi.js:1499:36)
    at HTMLDivElementImpl.querySelectorAll (~/jsdom-issue/node_modules/jsdom/lib/jsdom/living/nodes/ParentNode-impl.js:78:26)
    at HTMLDivElement.querySelectorAll (~/jsdom-issue/node_modules/jsdom/lib/jsdom/living/generated/Element.js:1119:58)
    at Object.<anonymous> (~/jsdom-issue/jsdom.js:9:18)
    at Module._compile (node:internal/modules/cjs/loader:1254:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1308:10)
@domenic domenic added the selectors CSS Selectors support label May 26, 2024
@domenic domenic added has to-upstream test This bug has a failing to-upstream web platform test waiting to be fixed and removed maybe fixed (add tests to confirm) labels Mar 30, 2025
domenic added a commit that referenced this issue Mar 30, 2025
The nwsapi update closes #3750, closes #3321, closes #3692, and closes #3818.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
has to-upstream test This bug has a failing to-upstream web platform test waiting to be fixed selectors CSS Selectors support
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants
0