Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Logical Selector regex does not handle some nested + chained selectors correctly #137

Closed
KindaOK opened this issue Dec 2, 2024 · 0 comments · Fixed by #138
Closed

Logical Selector regex does not handle some nested + chained selectors correctly #137

KindaOK opened this issue Dec 2, 2024 · 0 comments · Fixed by #138

Comments

@KindaOK
Copy link
Contributor

KindaOK commented Dec 2, 2024

Nested logical selectors are handled correctly. However, chained (adjacent?) ones are not. See minimal test cases below.

// all of these selectors match all elements

// does not crash and works correctly
:is(*)
:is(:is(*))

// crashes with SyntaxError unknown pseudo-class selector 
:is(*):is(*)
:is(:is(*):is(*))
is(*):is(:is(*))

There are many related issues that are all fundamentally due to this same issue.

Related Issues
#128
#127
#135 (comment)
#124
#123
#89

Someone on Issue #28 suggests using a parser instead of regex to handle these situations. I think that could work—using regex to find the initial logical selector and then a parser to segment the contents.

However, I experimented with a balanced parentheses matcher regex, and did get a working solution going with a configurable depth that fixes the above test cases and only fails on selectors deeper than its depth. I'm not sure about the performance characteristics of it though. I'd assume it's not the best, but it seems correct.

// depth=3
// crashes with SyntaxError unknown pseudo-class selector 
:is(:is(:is(:is(:is(*)))))

I've checked it against has basic, has relative, not complex, is where basic, and is nested, and had no regressions. PR is linked

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant