dperini / nwsapi

Fast CSS Selectors API Engine
MIT License
103 stars 35 forks source link

Child combinator `>` inside `:not()` is not a valid selector #107

Closed Nivani closed 3 months ago

Nivani commented 6 months ago

The following selector throws an error using nwsapi, but not in a web browser:

button:not(.k-dropdownlist > .k-button):not(.k-colorpicker > .k-button)

This selector is used by Kendo UI, a commercial component library.

I was able to narrow it down to the use of the child combinator > inside :not().

Node.js script that reproduces the issue:

const jsdom = require("jsdom");

const dom = new jsdom.JSDOM(`<!DOCTYPE html><p>Hello world</p>`);
const selectors = [
  "button:not(.k-dropdownlist > .k-button):not(.k-colorpicker > .k-button)",
  "button:not(.k-dropdownlist > .k-button)",
  "button:not(.k-dropdownlist)",
  ".k-dropdownlist > button.k-button",
];

selectors.forEach((selector) => {
  try {
    dom.window.document.querySelectorAll(selector);
    console.log(`✅ Selector "${selector}" is ok`);
  } catch (e) {
    console.log(`❌ Selector "${selector}" throws an error:`, e.message);
  }
});

Output:

❌ Selector "button:not(.k-dropdownlist > .k-button):not(.k-colorpicker > .k-button)" throws an error: 'button:not(.k-dropdownlist > .k-button):not(.k-colorpicker > .k-button)' is not a valid selector
❌ Selector "button:not(.k-dropdownlist > .k-button)" throws an error: 'button:not(.k-dropdownlist > .k-button)' is not a valid selector
✅ Selector "button:not(.k-dropdownlist)" is ok
✅ Selector ".k-dropdownlist > button.k-button" is ok

Tested with Node v20.9.0

I've seen other issues where selectors broke when upgrading from 2.2.2 to 2.2.3, but these don't work in 2.2.2 either.

dperini commented 4 months ago

@Nivani could you please check if the current "nwsapi" master branch here on github fixes the problem ? I haven't released a new package on NPM yet but if the problem is fixed I can plan a new release.

Nivani commented 4 months ago

@dperini thanks! It works when I use the master branch.

I've tested both the example above and the project that's using Kendo UI.

dperini commented 4 months ago

@Nivani thank you for the prompt answer. Will wait a few more confirmations to ensure I didn't create any regression or problem. Then I will release 2.2.10 on NPM and have others happy too. Forgive the delay in fixing this, appreciate your help and contribution.