dperini / nwsapi

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

logicalsel Rexexp selects incorrect values since 2.2.3 #88

Closed paulbrimicombe closed 3 months ago

paulbrimicombe commented 1 year ago

In version 2.2.3, the logicalsel regular expression changed from:

logicalsel: '(is|where|matches|not)\\x28\\s?([^()]*|[^\\x28]*\\x28[^\\x29]*\\x29)\\s?(?:\\x29|$)',

to

logicalsel: '(is|where|matches|not)\\x28\\s?([^\\[]*\\[[^\\]]*\\]|[^\\(]*\\([^\\)]*\\)|[^()]*)\\s?(?:\\x29|$)',

When matching a selector of the form:

[EDIT: this example was incorrect in the original bug report but should now be correct — apologies for the mistake!]

div:not(.main) a:not([class=unstyled-link]) {
    text-decoration: underline;
}

The old version would match not(.main) and not([class=unstyled-link]) separately but the new version matches the whole of not(.unstyled-links) a:not([class=unstyled-link)] as a single capture group. The [] in the second selector appears to be the problem — if I rewrite the second part of the selector as a:not(.unstyled-link) everything works as expected.

dperini commented 1 year ago

@paulbrimicombe it looks like the latest change I did to the Regular Expression solves for this selector and others too. Have you tried latest Github nwsapi commits ?

paulbrimicombe commented 1 year ago

@paulbrimicombe it looks like the latest change I did to the Regular Expression solves for this selector and others too. Have you tried latest Github nwsapi commits ?

@dperini the code in master definitely looks correct (comparing the matches made by the old and new regular expressions) but without a pre-release published to NPM I wouldn't be able to tell for sure!

dperini commented 1 year ago

@paulbrimicombe @ALL See issue #89 and commit 01216f85b9989ce0f1d5b0ee5ce28bb88ea8aaa3 for a new regular expression that should fix remaining failure cases.

paulbrimicombe commented 1 year ago

Hi @dperini , I've just checked v 2.2.5 and that looks good for us. It's harder to tell with the newer version because it's unreleased and I'd have to go in and hack node_modules to test it. Any chance of a pre-release published to npm?

dperini commented 1 year ago

@paulbrimicombe I need to release more fixes in 2.2.6 but it will be done soon.

dperini commented 4 months ago

@paulbrimicombe more fixes were committed to the "nwsapi" repository. Keep trying and report any issue you might find. Thank you for your feedback