Skip to content

Ignore quoted attribute values in the selector safety checks - #4

Merged
Dszae merged 1 commit into
mainfrom
fix/selector-safety-quoted-values
Nov 23, 2026
Merged

Dszae merged 1 commit into
mainfrom
fix/selector-safety-quoted-values

Conversation

@Dszae

@Dszae Dszae commented Nov 23, 2026

Copy link
Copy Markdown
Owner

checkSelectorSafety() looked for pseudo-classes and counted brackets across the whole selector, including inside quoted attribute values. Valid rules from the dashboard or a rules import were rejected:

Selector Before
div[class*="md:hidden"] (a Tailwind class) "The pseudo-class :hidden is not allowed."
[data-state="modal:open"] "The pseudo-class :open is not allowed."
[title='Disable adblock :('] "Selector has unbalanced brackets."
[data-x="a[b"] "Selector has unbalanced brackets."

Fix: quoted values are blanked out before the bracket and pseudo-class checks. Backslashes are already disallowed, so a quote can't be escaped. An unclosed quote such as [data-x="a].b, which was accepted before, is now rejected with its own reason. Pseudo-classes and pseudo-elements outside quotes are rejected as before.

Tests: in tests/unit/selector.test.ts, the four selectors above now pass. Rejected: :hover and ::before after a quoted value (unchanged behavior), and the unterminated quote (new). The 5 changed expectations fail on main. Typecheck, lint and Prettier are clean. npm test: 219 passed.

Co-authored-by: Claude noreply@anthropic.com

checkSelectorSafety() looked for pseudo-classes and counted brackets
across the whole selector, including inside quoted attribute values.
Valid rules were rejected:

- div[class*="md:hidden"] (a Tailwind class) and
  [data-state="modal:open"]: "The pseudo-class ":hidden" is not allowed."
- [title='Disable adblock :('] and [data-x="a[b"]: "Selector has
  unbalanced brackets."

Quoted values are now blanked out before the bracket and pseudo-class
checks. Backslashes are already disallowed, so a quote cannot be
escaped; a quote left unclosed ([data-x="a].b), which was accepted
before, is now rejected with its own reason. Pseudo-classes and
pseudo-elements outside quotes are rejected as before.

Co-authored-by: Claude <noreply@anthropic.com>
@Dszae
Dszae merged commit 4f5b53d into main Nov 23, 2026
2 checks passed
@Dszae
Dszae deleted the fix/selector-safety-quoted-values branch November 23, 2026 21:14
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 this pull request may close these issues.

1 participant