dperini / nwsapi

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

`SyntaxError: missing ) after argument list` due to missing escaping in `:has()` pseudo-class #111

Closed seckardt closed 3 months ago

seckardt commented 4 months ago

Parsing a selector of the following kind:

[attribute="value"]:has(...)

fails with a SyntaxError like this:

SyntaxError: missing ) after argument list

The error can be tracked down to this piece of code in nwsapi .js:

Function('s', F_INIT + '{' + head + vars + ';' + loop + 'return r;}')(Snapshot);

which ultimately generates code like this:

function(){"use strict";return function Resolver(c,f,x,r){var e,n,o;e=c;if(s.match("[class="div2"]",e) && e.querySelector("div")){if(((/^div2$/).test(e.getAttribute&&e.getAttribute("class"))==true)){r=true;}}return r;}}

which contains the problematic piece s.match("[class="div2"]",e) including the unescaped "[class="div2"]".

Seems like this issue was even brought up ealier by @Talor-A in https://github.com/dperini/nwsapi/issues/92#issuecomment-1861815928_, where the PR #92 otherwise seems to be unrelated.

dperini commented 3 months ago

Fix merged