dperini / nwsapi

Fast CSS Selectors API Engine
MIT License
105 stars 36 forks source link

Invalid selector parsed as valid #49

Closed carlos-hdzm closed 1 year ago

carlos-hdzm commented 3 years ago

I'm using jsdom@17.0.0, which has nwsapi@2.2.0 as a dependency. The following script runs without errors (it outputs true):

const { JSDOM } = require("jsdom");

const dom = new JSDOM(`
<!DOCTYPE html>
<body>
  <div class="section">
    <p class="text">
      <span class="important">IMPORTANT</span>
    </p>
  </div>
</body>
`);

const el = dom.window.document.querySelector(".section > > .important");
console.log(el.nodeName === "SPAN");

However, in a browser, .section > > .important is an invalid selector, as shown by this JS Bin. It throws a DOMException.

I suppose the issue is that the space between the two child combinators is converted to a wildcard selector, but that creates an inconsistency between different selector engines and environments.

dperini commented 1 year ago

@carlos-hdzm this seems to be fixed in release 2.2.3. I tested the selector "'.section > > .important')' to be throwing errors like a browser does.