Skip to content

fix(attributes): use CSS whitespace for token matching - #1911

Open
xiehuanyi wants to merge 1 commit into
fb55:masterfrom
xiehuanyi:fix/ascii-attribute-token-whitespace
Open

xiehuanyi wants to merge 1 commit into
fb55:masterfrom
xiehuanyi:fix/ascii-attribute-token-whitespace

Conversation

@xiehuanyi

@xiehuanyi xiehuanyi commented Oct 12, 2026 •

Copy link
Copy Markdown

[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.

View guided diff

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.

Copilot AI balanced review requested due to automatic review settings October 12, 2026 18:42

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.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 12, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-12T18:49:12.092697Z 66e3e2f PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@coderabbitai

coderabbitai Bot commented Oct 12, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Organization UI
  • Review profile: ASSERTIVE
  • Plan: Advanced
  • Run ID: 13e22888-348f-48a8-9316-855b5b9e8c0e

📥 Commits

Reviewing files that changed from the base of the PR and between 94edb4b and 66e3e2f.


📒 Files selected for processing (2)
  • src/attributes.ts
  • test/attributes.ts

Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 3 remain after this review.



📝 Walkthrough

Walkthrough

Attribute selector tokenization now treats only tab, line feed, form feed, carriage return, and space as separators. Tests cover matching with other whitespace characters and with the five recognized separators.

Changes

Attribute Selector Tokenization

Layer / File(s) Summary
Whitespace matching and token boundaries
src/attributes.ts, test/attributes.ts
The whitespace regex and ~= token-boundary regex now recognize five CSS whitespace characters. Tests verify that NBSP, em space, and vertical tab remain within tokens, while recognized whitespace splits tokens and produces a false function when included in a selector token.

Priority: ⬇️ Low

Estimated code review effort: 2 (Simple) | ~8 minutes

Change: Bug fix


Merge Risk: ⚪ Minimal · up to 66e3e

No actionable issue is identified in the attribute-token matching change; it is mergeable after normal checks.

Pre-merge checks | Passed 4 | Failed 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 1 functions across 2 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title clearly and concisely describes the main change: using CSS whitespace rules for attribute token matching.
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.

  • Fix all pre-merge checks with AI
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

A rabbit checks each token’s space,
And finds five separators in place.
A tab, a line feed, then a form,
Carriage return and space keep form.
NBSP stays; em space stays too,
Vertical tab remains there, too.

Comment @coderabbitai help to get the list of available commands.

@cubic-dev-ai cubic-dev-ai Bot 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.

No issues found across 2 files

View guided diff | Re-trigger cubic

@greptile-apps

greptile-apps Bot commented Oct 12, 2026 •

Copy link
Copy Markdown

RetriggerConfidence Score: 5/5

[Medium impact] The PR appears safe to merge; no actionable issues were found.

Summary

Updates [attr~=value] to use CSS whitespace instead of JavaScript whitespace.

  • Attribute token selectors split values only on CSS whitespace.

No actionable issues found. Tests were not run during this review.

Empty selector values: This behavior predates the change. Author xiehuanyi explicitly identified it as separate work covered by PR #1810.

Reviews (1) · Last reviewed commit: "fix(attributes): use CSS whitespace for ..." · Reviewed by Greptile

This branch has not been deployed

No deployments
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.

2 participants