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
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 strips valid CSS unicode escapes from string literals. This fixes broken iconfont `content` values caused by the autofix.
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,31 @@
}
.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"
}
/* hex digit 8-9 (not just a-f) */
.h::after {
content: "\89"
}
/* hex prefix + non-hex suffix: \ee is valid 2-digit escape, zaf is literal */
.i::after {
content: "\eezaf"
}
.j::after {
content: "\edk"
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,33 @@ 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"
}
/* hex digit 8-9 (not just a-f) */
.h::after {
content: "\89"
}
/* hex prefix + non-hex suffix: \ee is valid 2-digit escape, zaf is literal */
.i::after {
content: "\eezaf"
}
.j::after {
content: "\edk"
}
```

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