fix(attributes): use CSS whitespace for token matching

XI
4d ago
+45-2

[class~=foo] currently matches class="foo\u00a0bar", while [class~="foo\u00a0bar"] cannot match the complete token. JavaScript \s includes NBSP, EM SPACE and vertical tab; CSS uses only TAB, LF, FF, CR and SPACE as whitespace (Selectors §3.7, attribute selectors).

Use those five characters for both the ~= selector-value check and attribute token boundaries. The tests cover non-CSS whitespace as token content, case-insensitive matching, and all five CSS separators.

Validation: the new suite fails in three cases before the change; npm test passes with 225 tests and one existing skipped test, including ESLint, TypeScript and Biome checks. npm run build and git diff --check pass.

Prepared and tested with OpenAI Codex assistance. This covers token whitespace; the separate empty-value issue already has PR #1810.

Summary by CodeRabbit

  • Bug Fixes
    • Attribute selectors now split tokens only on CSS whitespace characters. Other whitespace-like characters remain part of the token, improving match accuracy.