Skip to content
Open
Show file tree
Hide file tree
Changes from 2 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
5 changes: 5 additions & 0 deletions .changeset/fix-css-unicode-escape.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@biomejs/biome": patch
---

Fixed [#9385](https://github.com/biomejs/biome/issues/9385): the [`noUselessEscapeInString`](https://biomejs.dev/linter/rules/no-useless-escape-in-string/) rule no longer removes valid CSS unicode escape sequences (e.g. `\e7bb`, `\e644`) from string literals. Previously, backslashes followed by hex digits `8``9` and `a``f`/`A``F` were incorrectly treated as useless escapes, breaking iconfont `content` properties.
Copy link
Contributor

Choose a reason for hiding this comment

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

oh good, the ai figured out it was hex sequence that's allowed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Simplified the changeset to be more user-facing as suggested. Also added test cases for \89, \eezaf, and \edk to cover the edge cases you and @dyc3 brought up.

Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ declare_lint_rule! {
///
/// ```css,expect_diagnostic
/// a::after {
/// content: "\a"
/// content: "\g"
/// }
/// ```
///
Expand All @@ -43,6 +43,12 @@ declare_lint_rule! {
/// }
/// ```
///
/// ```css
/// a::after {
/// content: "\e7bb"
/// }
/// ```
///
pub NoUselessEscapeInString {
version: "2.0.0",
name: "noUselessEscapeInString",
Expand Down Expand Up @@ -109,16 +115,17 @@ fn next_useless_escape(str: &str, quote: u8) -> Option<usize> {
b'^'
| b'\r'
| b'\n'
| b'0'..=b'7'
| b'\\'
| b'b'
| b'f'
| b'n'
| b'r'
| b't'
| b'u'
| b'v'
| b'x' => {}
| b'x'
// CSS unicode escape: \ followed by 1-6 hex digits
| b'0'..=b'9'
| b'a'..=b'f'
| b'A'..=b'F' => {}
// Preserve escaping of Unicode characters U+2028 and U+2029
0xE2 => {
if !(matches!(it.next(), Some((_, 0x80)))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
.a::after {
content: /*before*/ "useless \a" /*after*/
content: /*before*/ "useless \g" /*after*/
}
.b::after {
content: "useless \'"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ expression: invalid.css
# Input
```css
.a::after {
content: /*before*/ "useless \a" /*after*/
content: /*before*/ "useless \g" /*after*/
}
.b::after {
content: "useless \'"
Expand All @@ -19,7 +19,7 @@ invalid.css:2:35 lint/suspicious/noUselessEscapeInString FIXABLE ━━━━
! The character doesn't need to be escaped.

1 │ .a::after {
> 2 │ content: /*before*/ "useless \a" /*after*/
> 2 │ content: /*before*/ "useless \g" /*after*/
│ ^
3 │ }
4 │ .b::after {
Expand All @@ -28,7 +28,7 @@ invalid.css:2:35 lint/suspicious/noUselessEscapeInString FIXABLE ━━━━

i Safe fix: Unescape the character.

2 │ ····content:·/*before*/·"useless·\a"·/*after*/
2 │ ····content:·/*before*/·"useless·\g"·/*after*/
│ -

```
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,20 @@
}
.b::after {
content: "\t"
}
/* CSS unicode escapes: \ followed by 1-6 hex digits */
.c::after {
content: "\e7bb"
}
.d::after {
content: "\e644"
}
.e::after {
content: "\a"
}
.f::after {
content: "\0a"
}
.g::after {
content: "\AB12CD"
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,22 @@ expression: valid.css
.b::after {
content: "\t"
}
/* CSS unicode escapes: \ followed by 1-6 hex digits */
.c::after {
content: "\e7bb"
}
.d::after {
content: "\e644"
}
.e::after {
content: "\a"
}
.f::after {
content: "\0a"
}
.g::after {
content: "\AB12CD"
}
```

_Note: The parser emitted 2 diagnostics which are not shown here._