You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 374d191
Browse filesBrowse the repository at this point in the historyBrowse files
Reject arbitrary values with unbalanced parens or brackets (#20577)
<!--
👋 Hey, thanks for your interest in contributing to Tailwind!
**Please ask first before starting work on any significant new
features.**
It's never a fun experience to have your pull request declined after
investing a lot of time and effort into a new feature. To avoid this
from happening, we request that contributors create a discussion to
first discuss any significant new features.
For more info, check out the contributing guide:
https://github.com/tailwindlabs/tailwindcss/blob/main/.github/CONTRIBUTING.md
-->
## Summary
Candidates with an unclosed `(` or `[` inside an arbitray value are
accepted and generated invalid css:
```css
`w-[calc(20px]` -> `width: calc()20px;`
`w-[(]` -> `width: ();`
```
Tailwind play with the bug reproduced:
https://play.tailwindcss.com/vQyd5Lh4bz
<img width="781" height="1015" alt="Captura de Tela 2026-10-14 às 19 43
48"
src="https://github.com/user-attachments/assets/26039daf-000a-44f0-8fbd-3f4c1e28115c"
/>
Why this was happening:
1. `isValidArbitrary` documents that unbalanced values are not allowed,
but it never checked that every `(` and `[` was closed, and it ignored a
mismatched closer such as `(]`.
2. the parser validated the value after `decodeArbitraryValue`, and the
value parser turns `calc(20px` into `calc()20px`, so the validator only
saw a balanced string.
This pr:
- Makes `isValidArbitrary` return `false` for a mismatched closing char
and for any unclosed `(` or `[` at the end of the value, a mismatched
`}` is still tolerated, since `{` is not tracked on the stack, e.g.
`var(--a, {})`
- validates the raw value before decoding, via a small
`decodeValidArbitraryValue` helper at all places where an arbitrary
value is parsed, like arbitrary properties, utility values, modifiers ,
arbitrary variants and functional variants suck `[...]` and `(...)`
this change is also making the js parser agree with the rust scanner,
which already rejects unbalanced brackets (check
`arbitrary_value_machine.rs`), this bug is reachable wherever the js
parser receives strings directly, such tailwind play or
`compile().build([...])`
## Test plan
- added test to `candidate.test.ts` covering unbalanced values for
utility values, arbitrary properties, modifiers, arbitrary variants and
functional variants, they fail on `main` and pass with the change made
here
- Some existent tests contained unbalanced inputs taht only passed
because the value parser repaired or dropped the bad paren
`pnpm vitest run src/candidate.test.ts`
`pnpm vitest run src/index.test.ts`
---------
Co-authored-by: Robin Malfait <[email protected]>
Copy file name to clipboardExpand all lines: CHANGELOG.md
+1Lines changed: 1 addition & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -50,6 +50,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
50
50
- Canonicalization: don't collapse utilities into a utility that uses another theme variable with the same default value (e.g. `mt-card mb-card` → `my-card`, not `my-4`) ([#20574](https://github.com/tailwindlabs/tailwindcss/pull/20574))
51
51
- Ensure `@tailwindcss/postcss` rewrites relative `url(…)`s of stylesheets that are inlined before it runs (e.g. `@import`s in Vite) in optimized builds ([#20576](https://github.com/tailwindlabs/tailwindcss/pull/20576))
52
52
- Drop nested rules that put a combinator after a pseudo-element when using pseudo-element variants (e.g. `selection:*` on a utility with a nested `& > *` rule) ([#20575](https://github.com/tailwindlabs/tailwindcss/pull/20575))
53
+
- Don't generate CSS for arbitrary values with unbalanced parentheses or brackets (e.g. `w-[calc(1px]` or `[--x:a[b]`) ([#20577](https://github.com/tailwindlabs/tailwindcss/pull/20577))
0 commit comments