Skip to content
Merged
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Fixed

- Improve canonicalizations for `tracking-*` utilities ([#19827](https://github.com/tailwindlabs/tailwindcss/pull/19827))
- Fix crash due to invalid characters in candidate ([#19829](https://github.com/tailwindlabs/tailwindcss/pull/19829))

## [4.2.2] - 2026-03-18

Expand Down
8 changes: 8 additions & 0 deletions packages/tailwindcss/src/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1501,6 +1501,14 @@ describe('Parsing theme values from CSS', () => {
`)
})

// https://github.com/tailwindlabs/tailwindcss/issues/19786
test('out-of-range escaped CSS variable candidates do not crash the build', async () => {
// Shouldn't crash
await run([
String.raw`--Coding-Projects-CharacterMapper-Master-Workspace\d8819554-4725-4235-9d22-2d0ed572e924`,
])
})

test('`@keyframes` in `@theme` are hoisted', async () => {
expect(
await compileCss(
Expand Down
10 changes: 10 additions & 0 deletions packages/tailwindcss/src/utils/escape.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,14 @@ describe('unescape', () => {
test('removes backslashes', () => {
expect(unescape(String.raw`red-1\/2`)).toMatchInlineSnapshot(`"red-1/2"`)
})

test('replaces out-of-range escaped code points', () => {
expect(
unescape(
String.raw`--Coding-Projects-CharacterMapper-Master-Workspace\d8819554-4725-4235-9d22-2d0ed572e924`,
),
).toMatchInlineSnapshot(
`"--Coding-Projects-CharacterMapper-Master-Workspace�54-4725-4235-9d22-2d0ed572e924"`,
)
})
})
22 changes: 19 additions & 3 deletions packages/tailwindcss/src/utils/escape.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,24 @@ export function escape(value: string) {

export function unescape(escaped: string) {
return escaped.replace(/\\([\dA-Fa-f]{1,6}[\t\n\f\r ]?|[\S\s])/g, (match) => {
return match.length > 2
? String.fromCodePoint(Number.parseInt(match.slice(1).trim(), 16))
: match[1]
if (match.length <= 2) {
return match[1]
}

let codePoint = Number.parseInt(match.slice(1).trim(), 16)

if (
// Invalid codepoint: https://infra.spec.whatwg.org/#code-point
codePoint === 0x0000 ||
codePoint > 0x10ffff ||
// Is surrogate: https://infra.spec.whatwg.org/#leading-surrogate
// - A leading surrogate is a code point that is in the range U+D800 to U+DBFF, inclusive.
// - A trailing surrogate is a code point that is in the range U+DC00 to U+DFFF, inclusive.
(codePoint >= 0xd800 && codePoint <= 0xdfff)
) {
return '\uFFFD'
}

return String.fromCodePoint(codePoint)
})
}