Skip to content
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

Query selector, use of ~ in :not() throws #55

Open
Banou26 opened this issue May 23, 2022 · 6 comments
Open

Query selector, use of ~ in :not() throws #55

Banou26 opened this issue May 23, 2022 · 6 comments

Comments

@Banou26
Copy link

Banou26 commented May 23, 2022

import { JSDOM } from 'jsdom'

const doc = new JSDOM(`
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
</head>
<body>
</body>
</html>
`).window.document

doc.querySelector('.js-sns-icon-container ~ h2 ~ h2 ~ .spaceit_pad:not(.js-sns-icon-container ~ h2 ~ h2 ~ h2 ~ .spaceit_pad)')

throws

'.js-sns-icon-container ~ h2 ~ h2 ~ .spaceit_pad:not(.js-sns-icon-container ~ h2 ~ h2 ~ h2 ~ .spaceit_pad)' is not a valid selector

Trying to query for .js-sns-icon-container ~ h2 ~ h2 ~ .spaceit_pad:not(.js-sns-icon-container ~ h2 ~ h2 ~ h2 ~ .spaceit_pad) in browsers work completly fine (Tried in chrome and FF).

@Banou26 Banou26 changed the title Query selector, use of ~ in :not() throws Query selector, use of ~ in :not() throws May 23, 2022
@cryosis7
Copy link

cryosis7 commented Jun 8, 2022

I am experiencing a similar issue with table:not(table table) i.e. All tables that are not descendants of another table.
My difference was that instead of throwing an error, it would not parse the selector in the :not parameters as a complex selector (As is permitted in CSS Selectors Level 4)
I observed the :not would only parse the last tag, for instance if my selector was ul:not(p ul) it would parse it as ul:not(ul)

@slavaleleka
Copy link
Contributor

slavaleleka commented Dec 16, 2022

the same with child combinator > and adjacent sibling combinator + inside :not() pseudo-class arg
div:not(div > span)
div:not(h1 + p)

there is no error in browser:

@svarzee
Copy link

svarzee commented Jan 22, 2023

I came across the same issue. It seems selector validation is broken. If you really need it to work you can try disabling validation, keep in mind it is an ugly hack though and it might not work for everyone:

In node_modules/nwsapi/src/nwsapi.js replace:
reValidator = RegExp(standardValidator, 'g');
with
reValidator = RegExp('.*', 'g');

@dperini dperini closed this as completed in 12f9f59 Apr 6, 2023
@svarzee
Copy link

svarzee commented Apr 24, 2024

@dperini The issue shouldn't be closed, the problem wasn't fixed. Validation still fails for valid selectors mentioned in this issue.

@dperini dperini reopened this Apr 25, 2024
@dperini
Copy link
Owner

dperini commented Apr 25, 2024

@svarzee
you are correct I should at least have pushed the code to fix this before closing.
However just for you to know I already have the code for that and I am in the process to get this fixed.

@dperini
Copy link
Owner

dperini commented Apr 30, 2024

@Banou26
I pushed a commit for the problem you have submitted (b9da534) hope it fixes your issue.
It could be of help if you can check the github master repository and confirm the fix.
Thank you for your time and help.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants