Repository navigation
Allow escaped characters in the class name - #1658
samuil-banti-wpenigne wants to merge 8 commits into
Conversation
There was a problem hiding this comment.
🟡 Changes recommended
The escape helper repeatedly copies a growing array, introducing quadratic overhead for long compound selectors.
1 open issue
What changed in this PR
This PR extends selector parsing to support escaped structural characters in class names, including Tailwind CSS v4 arbitrary variants.
Changes:
- Apply escape detection before interpreting brackets, parentheses, braces, and selector separators.
- Add regression tests for escaped characters, backslash parity, and selector boundaries.
- Document the parsing improvement in the changelog.
| File | Description |
|---|---|
| tests/Unit/Property/SelectorTest.php | Test escaped selectors and component boundaries. |
| tests/Unit/Property/Selector/CompoundSelectorTest.php | Test escaped structural characters and stop-character handling. |
| src/Property/Selector/CompoundSelector.php | Extend escape detection across structural characters. |
| CHANGELOG.md | Record support for escaped selector characters. |
Review effort: Balanced
Co-authored-by: Copilot Autofix powered by AI <[email protected]>
JakeQZ
left a comment
There was a problem hiding this comment.
Thanks @samuil-banti-wpenigne, this looks great, with excellent tests.
I've just spent several hours trying to decipher the CSS spec, which is as clear as mud (but more interesting than trying to patch up web servers ;)). Think I've got to the bottom of it. We're not handling the \r and \n cases correctly, as they cannot be escaped, but I think those should be left alone for now to be addressed in a future PR. Most other characters can be escaped and this change seems to address that very well.
I've made a couple of other minor suggested improvements.
Some may belong in the |
JakeQZ
left a comment
There was a problem hiding this comment.
This LGTM now, thanks for contributing <3.
|
@oliverklee, do you see any other issues? |

Tailwind CSS v4 may contain square brackets in the class names i.e.
Other valid characters are also affected by the parser at this point:
So the goal of the PR is to enable parsing of such selectors.