Skip to content

Commit 52325a8

Browse files
authored
Only compile arbitrary values ending in ] (#15503)
This PR ensures that if you are using an arbitrary value such as `bg-[red` that it only compiles if it's a properly closed arbitrary value. Currently what happens is that it assumes the `]` is there, and cuts it off. This then results in the `bg-[red` to be compiled as: ```css .bg-\[red { background-color: re; } ``` Note how the `d` in `red` is cut off. That's the assumption that the `]` is there. This PR fixes that by ensuring that the arbitrary value is properly closed. Fixes: #15484
1 parent 9075db0 commit 52325a8

File tree

3 files changed

+11
-0
lines changed

3 files changed

+11
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1313
- Don’t detect arbitrary properties when preceded by an escape ([#15456](https://github.com/tailwindlabs/tailwindcss/pull/15456))
1414
- Fix incorrectly named `bg-round` and `bg-space` utilities to `bg-repeat-round` to `bg-repeat-space` ([#15462](https://github.com/tailwindlabs/tailwindcss/pull/15462))
1515
- Fix `inset-shadow-*` suggestions in IntelliSense ([#15471](https://github.com/tailwindlabs/tailwindcss/pull/15471))
16+
- Only compile arbitrary values ending in `]` ([#15503](https://github.com/tailwindlabs/tailwindcss/pull/15503))
1617

1718
### Changed
1819

packages/tailwindcss/src/candidate.test.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -540,6 +540,13 @@ it('should parse a utility with an arbitrary value', () => {
540540
`)
541541
})
542542

543+
it('should not parse a utility with an incomplete arbitrary value', () => {
544+
let utilities = new Utilities()
545+
utilities.functional('bg', () => [])
546+
547+
expect(run('bg-[#0088cc', { utilities })).toMatchInlineSnapshot(`[]`)
548+
})
549+
543550
it('should parse a utility with an arbitrary value with parens', () => {
544551
let utilities = new Utilities()
545552
utilities.functional('bg', () => [])

packages/tailwindcss/src/candidate.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -438,6 +438,9 @@ export function* parseCandidate(input: string, designSystem: DesignSystem): Iter
438438
let valueIsArbitrary = startArbitraryIdx !== -1
439439

440440
if (valueIsArbitrary) {
441+
// Arbitrary values must end with a `]`.
442+
if (value[value.length - 1] !== ']') return
443+
441444
let arbitraryValue = decodeArbitraryValue(value.slice(startArbitraryIdx + 1, -1))
442445

443446
// Extract an explicit typehint if present, e.g. `bg-[color:var(--my-var)])`

0 commit comments

Comments
 (0)