Skip to content

Ignore arbitrary values with unbalanced curly braces - #20766

Open
feliciovcm wants to merge 1 commit into
tailwindlabs:mainfrom
feliciovcm:reject-unbalanced-curlies
Open

feliciovcm wants to merge 1 commit into
tailwindlabs:mainfrom
feliciovcm:reject-unbalanced-curlies

Conversation

@feliciovcm

Copy link
Copy Markdown

Summary

Arbitrary values with a { that is never closed are accepted and end up in the generated CSS:

.w-\[\{\] {
  width: {;
}

The { opens a block, so rules that come after it are swallowed. Chromium parses .w-\[\{\] { width: {; } .underline { text-decoration-line: underline; } into a single rule, with .underline nested inside it.

Nested values like w-[calc({)], bg-(--a,{) or [--a:{] are accepted too, and a nested } like w-[calc(})] generates width: calc(});.

#20577 rejected unbalanced parens and brackets, but left { off the stack so that a top-level } (e.g. [&{color:red}]:flex) stays invalid. This PR rejects a top-level { right away, which keeps that behavior, and tracks nested curlies on the stack so they have to be balanced. Balanced nested curlies like var(--a,{}) are still allowed.

The Oxide scanner does not extract these candidates, so this affects callers that pass candidates to the JS compiler directly, e.g. compile().build([…]).

Test plan

Added cases to candidate.test.ts. They fail without the fix (5 failures), and all pass with it:

npx vitest run packages/tailwindcss/src
Test Files  45 passed (45)
     Tests  5543 passed | 1 skipped (5544)

prettier --check on the changed files and node scripts/changelog.mjs check pass.

Output of build(['w-[{]', 'underline']), before:

.w-\[\{\] {
  width: {;
}
.underline {
  text-decoration-line: underline;
}

After:

.underline {
  text-decoration-line: underline;
}

@feliciovcm
feliciovcm requested a review from a team as a code owner November 25, 2026 15:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant