nwsapi icon indicating copy to clipboard operation
nwsapi copied to clipboard

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

Open Banou26 opened this issue 3 years ago • 6 comments

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 avatar May 23 '22 23:05 Banou26

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)

cryosis7 avatar Jun 08 '22 00:06 cryosis7

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:

slavaleleka avatar Dec 16 '22 16:12 slavaleleka

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');

svarzee avatar Jan 22 '23 18:01 svarzee

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

svarzee avatar Apr 24 '24 19:04 svarzee

@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 avatar Apr 25 '24 07:04 dperini

@Banou26 I pushed a commit for the problem you have submitted (b9da5347250ca7c9796f70c86189dfbeacb9aa18) 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.

dperini avatar Apr 30 '24 11:04 dperini