Repository navigation
Decode single-digit hexadecimal CSS escapes - #20591
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info
Walkthrough
Priority: ➖ Normal Merge Risk: ⚪ Minimal · up to
|
[Medium impact] The PR appears safe to merge; no actionable issues were found. Reviews (1) · Last reviewed commit: "Decode single-digit hexadecimal CSS esca..." · Reviewed by Greptile |
|
Hey! Thanks for the PR. Before we look at this further: is there a real problem behind it that you run into? For example a project where a theme variable, an If so, can you share the code or the setup (a small reproduction is perfect)? That helps us judge whether the change is worth it, and makes sure that we test the case that matters to you. Sent by an AI assistant on behalf of @RobinMalfait. |
|
Thanks for taking a look! I don't have a real project where I've run into this. I found it while reading the escape decoder, so this is a synthetic reproduction rather than a production bug report. The compilation test in the PR uses this input: @theme {
--color-\0: red;
}
@tailwind utilities;and builds the candidate const compiler = await compile(String.raw`
@theme { --color-\0: red; }
@tailwind utilities;
`)
const output = compiler.build([String.raw`bg-(--color-\0)`])With the original decoder at :root, :host {
--color-0: red;
}
.bg-\(--color-\\0\) {
background-color: var(--color-\0);
}The declaration and reference don't name the same variable: CSS resolves I reran this against both implementations: the assertion for pnpm exec vitest run --project tailwindcss packages/tailwindcss/src/index.test.ts -t 'single-digit hexadecimal'I don't currently have evidence of an application using these names, though, so I understand the question about practical impact. |
RobinMalfait
left a comment
There was a problem hiding this comment.
Thanks for the PR, and for the clear write-up of the escape handling!
Sent by an AI assistant on behalf of @RobinMalfait.
Adds the changelog entry for #20591. The entry was missing because the fork of that PR did not allow maintainer edits. <sub>Sent by an AI assistant on behalf of @RobinMalfait.</sub>
Summary
unescapetreats every two-character match as a simple character escape, including a backslash followed by a single hexadecimal digit. For example,\abecomes the letterainstead of U+000A, and\0becomes0instead of U+FFFD.Distinguish hexadecimal escapes from simple escapes using separate capture groups. This preserves the existing handling of one-to-six hex digits, optional trailing whitespace, and invalid code points.
This also fixes theme variable normalization:
@theme { --color-\0: red; }currently registers--color-0, while the CSS referencevar(--color-\0)refers to a different identifier. Add a compilation regression test alongside the helper tests.Reference: CSS Syntax — consume an escaped code point.
Test plan
pnpm exec vitest run --project tailwindcss packages/tailwindcss/src/utils/escape.test.ts— 19 passed.pnpm exec vitest run --project tailwindcss packages/tailwindcss/src/index.test.ts -t 'single-digit hexadecimal'— 1 passed.pnpm exec vitest run --project tailwindcss— 5,158 passed, 3 failed, 1 skipped. The same three snapshot failures were verified on unmodified upstreamf7f47f8: CSS mixins, rounded utilities, and theme string indexing.