Skip to content

Allow escaped characters in the class name - #1658

Open
samuil-banti-wpenigne wants to merge 8 commits into
MyIntervals:mainfrom
samuil-banti-wpenigne:enable-escaped-symbols-in-the-class-names
Open

samuil-banti-wpenigne wants to merge 8 commits into
MyIntervals:mainfrom
samuil-banti-wpenigne:enable-escaped-symbols-in-the-class-names

Conversation

@samuil-banti-wpenigne

Copy link
Copy Markdown
Contributor

Tailwind CSS v4 may contain square brackets in the class names i.e.

.\[\&
_\[data-piko-package\=review-card\]\]\:px-\[25px\] [data-piko-package=review-card]{pa
dding-inline:25px}

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.

@coveralls

coveralls commented Oct 22, 2026 •

Copy link
Copy Markdown

Coverage Status

coverage: 75.471% (+0.04%) from 75.43% — samuil-banti-wpenigne:enable-escaped-symbols-in-the-class-names into MyIntervals:main

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 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

Comment thread src/Property/Selector/CompoundSelector.php Outdated

@JakeQZ JakeQZ left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread src/Property/Selector/CompoundSelector.php Outdated
Comment thread src/Property/Selector/CompoundSelector.php Outdated
Comment thread src/Property/Selector/CompoundSelector.php Outdated
@JakeQZ

JakeQZ commented Oct 22, 2026

Copy link
Copy Markdown
Collaborator

excellent tests.

Some may belong in the Functional rather than Unit division due to their dependency on other classes, but that can be tidied-up post-PR, as I think we have other misplaced tests.

@JakeQZ JakeQZ left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This LGTM now, thanks for contributing <3.

@JakeQZ

JakeQZ commented Oct 27, 2026

Copy link
Copy Markdown
Collaborator

@oliverklee, do you see any other issues?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants