Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions .changeset/fix-unicode-range-recovery.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
---
"@biomejs/biome": patch
---

Improved CSS parser recovery for invalid `unicode-range` values that mix wildcard ranges with range intervals. For example, Biome now reports clearer diagnostics for invalid syntax like:

```css
unicode-range: U+11???-2??;
unicode-range: U+11???-;
```

with diagnostics such as:

```text
× Wildcard ranges cannot be combined with a range interval.
> unicode-range: U+11???-2??;
^

× Expected a codepoint but instead found ';'.
> unicode-range: U+11???-;
^
```
32 changes: 31 additions & 1 deletion crates/biome_css_parser/src/syntax/property/unicode_range.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,24 @@ pub(crate) fn parse_unicode_range(p: &mut CssParser) -> ParsedSyntax {
p.bump_with_context(T!["U+"], CssLexContext::UnicodeRange);

// Checks if the parser is positioned to parse a Unicode range wildcard.
// A wildcard cannot be combined with a range interval. For example, `U+????-U+????` is invalid.
// A wildcard cannot be combined with a range interval. For example, `U+????-2222` is invalid.
if is_at_unicode_range_wildcard(p) {
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();
p.error(wildcard_range_interval_not_allowed(p, range));
p.bump_with_context(T![-], CssLexContext::UnicodeRange);

if parse_unicode_codepoint(p).is_absent() && parse_unicode_range_wildcard(p).is_absent()
{
p.error(expected_codepoint(p, p.cur_range()));
}

return Present(m.complete(p, CSS_BOGUS_UNICODE_RANGE_VALUE));
}

return Present(m.complete(p, CSS_UNICODE_RANGE));
}

Expand Down Expand Up @@ -173,6 +187,22 @@ pub(crate) fn wildcard_not_allowed(p: &CssParser, range: TextRange) -> ParseDiag
)
}

/// Provides a diagnostic for invalid use of a wildcard range with an explicit interval.
///
/// Example: `U+11???-2222`
pub(crate) fn wildcard_range_interval_not_allowed(
p: &CssParser,
range: TextRange,
) -> ParseDiagnostic {
p.err_builder(
"Wildcard ranges cannot be combined with a range interval.",
range,
)
.with_hint(
"Use either a wildcard range (e.g. `U+11???`) or an explicit interval (e.g. `U+1100-2222`).",
)
}

/// Generates a parse diagnostic for an expected "codepoint" error message at the given range.
pub(crate) fn expected_codepoint(p: &CssParser, range: TextRange) -> ParseDiagnostic {
expected_node("codepoint", range, p)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
unicode-range: U+;
unicode-range: U+1111111111;
unicode-range: U+11???-2222;
unicode-range: U+11???-2??;
unicode-range: U+11???-;
unicode-range: U+11-2??;
unicode-range: U+11-;
}
Loading