Skip to content

fix(css): improve unicode wildcard range recovery#9354

Open
denbezrukov wants to merge 2 commits intomainfrom
db/unicode
Open

fix(css): improve unicode wildcard range recovery#9354
denbezrukov wants to merge 2 commits intomainfrom
db/unicode

Conversation

@denbezrukov
Copy link
Contributor

This PR was created with AI assistance (Codex).

Summary

Improves CSS unicode-range error recovery for invalid values that mix wildcard ranges with
explicit intervals.

Test Plan

cargo test -p biome_css_parser

@changeset-bot
Copy link

changeset-bot bot commented Mar 5, 2026

🦋 Changeset detected

Latest commit: 2825e76

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 13 packages
Name Type
@biomejs/biome Patch
@biomejs/cli-win32-x64 Patch
@biomejs/cli-win32-arm64 Patch
@biomejs/cli-darwin-x64 Patch
@biomejs/cli-darwin-arm64 Patch
@biomejs/cli-linux-x64 Patch
@biomejs/cli-linux-arm64 Patch
@biomejs/cli-linux-x64-musl Patch
@biomejs/cli-linux-arm64-musl Patch
@biomejs/wasm-web Patch
@biomejs/wasm-bundler Patch
@biomejs/wasm-nodejs Patch
@biomejs/backend-jsonrpc Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@github-actions github-actions bot added A-Parser Area: parser L-CSS Language: CSS labels Mar 5, 2026
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 5, 2026

Walkthrough

This PR improves the CSS parser's unicode-range recovery when a wildcard range is followed by a hyphen. It adds a recovery path that emits a wildcard_range_interval_not_allowed diagnostic, consumes the trailing hyphen, attempts to parse a codepoint or wildcard, and falls back to emitting an expected_codepoint diagnostic and returning CSS_BOGUS_UNICODE_RANGE_VALUE if recovery fails. The change introduces the wildcard_range_interval_not_allowed helper, augments the expected_codepoint diagnostic with an extra hint, updates a comment example, and adds two error tests (unicode-range: U+11???-2??; and unicode-range: U+11???-;).

Suggested reviewers

  • denbezrukov
  • dyc3
🚥 Pre-merge checks | ✅ 2
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main change: improving CSS unicode wildcard range error recovery.
Description check ✅ Passed The description directly relates to the changeset, explaining the improvement to CSS unicode-range error recovery and the test plan.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch db/unicode

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

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

@codspeed-hq
Copy link

codspeed-hq bot commented Mar 5, 2026

Merging this PR will not alter performance

✅ 29 untouched benchmarks
⏩ 187 skipped benchmarks1


Comparing db/unicode (2825e76) with main (5046d2b)

Open in CodSpeed

Footnotes

  1. 187 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
crates/biome_css_parser/src/syntax/property/unicode_range.rs (1)

73-75: Use a wider span for this diagnostic.

Nice recovery path, but p.cur_range() here highlights only -. Spanning from the wildcard start through the hyphen would better point at the offending construct.

Suggested tweak
-    if is_at_unicode_range_wildcard(p) {
-        parse_unicode_range_wildcard(p).ok();
+    if is_at_unicode_range_wildcard(p) {
+        let wildcard_start = p.cur_range().start();
+        parse_unicode_range_wildcard(p).ok();

         if p.at(T![-]) {
             // Wildcards cannot start a range interval (e.g. `U+????-2222`); consume the tail to recover.
-            let range = p.cur_range();
+            let range = TextRange::new(wildcard_start, p.cur_range().end());
             p.error(wildcard_range_interval_not_allowed(p, range));
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@crates/biome_css_parser/src/syntax/property/unicode_range.rs` around lines 73
- 75, The diagnostic currently uses p.cur_range() which only highlights the
hyphen; change it to span from the wildcard start through the hyphen by
computing a range that begins at the wildcard token start and ends at the
current position (e.g. capture token start before consuming the wildcard or use
an available previous/start range API), then pass that wider range into
wildcard_range_interval_not_allowed instead of p.cur_range(); keep the
subsequent p.bump_with_context(T![-], CssLexContext::UnicodeRange) unchanged.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@crates/biome_css_parser/src/syntax/property/unicode_range.rs`:
- Around line 73-75: The diagnostic currently uses p.cur_range() which only
highlights the hyphen; change it to span from the wildcard start through the
hyphen by computing a range that begins at the wildcard token start and ends at
the current position (e.g. capture token start before consuming the wildcard or
use an available previous/start range API), then pass that wider range into
wildcard_range_interval_not_allowed instead of p.cur_range(); keep the
subsequent p.bump_with_context(T![-], CssLexContext::UnicodeRange) unchanged.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: ce0ec6e1-e6b1-4d04-95d2-e0540aab40ac

📥 Commits

Reviewing files that changed from the base of the PR and between 8d08cec and 2825e76.

📒 Files selected for processing (1)
  • crates/biome_css_parser/src/syntax/property/unicode_range.rs

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

Labels

A-Parser Area: parser L-CSS Language: CSS

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants