From 0e2a2f884506b5cebdf024efff3d0c2b7f4094f1 Mon Sep 17 00:00:00 2001 From: Robin Malfait Date: Sun, 29 Dec 2024 01:35:41 +0100 Subject: [PATCH 1/3] add failing test --- packages/tailwindcss/src/candidate.test.ts | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/packages/tailwindcss/src/candidate.test.ts b/packages/tailwindcss/src/candidate.test.ts index 4242b11b7164..848590a46a88 100644 --- a/packages/tailwindcss/src/candidate.test.ts +++ b/packages/tailwindcss/src/candidate.test.ts @@ -540,6 +540,13 @@ it('should parse a utility with an arbitrary value', () => { `) }) +it('should not parse a utility with an incomplete arbitrary value', () => { + let utilities = new Utilities() + utilities.functional('bg', () => []) + + expect(run('bg-[#0088cc', { utilities })).toMatchInlineSnapshot(`[]`) +}) + it('should parse a utility with an arbitrary value with parens', () => { let utilities = new Utilities() utilities.functional('bg', () => []) From 2457083fd475a0a3e7d6becab26691fc2c765a96 Mon Sep 17 00:00:00 2001 From: Robin Malfait Date: Sun, 29 Dec 2024 01:35:51 +0100 Subject: [PATCH 2/3] ensure arbitrary values end with `]` --- packages/tailwindcss/src/candidate.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/packages/tailwindcss/src/candidate.ts b/packages/tailwindcss/src/candidate.ts index 26def1bff0ee..6c15b2ba6163 100644 --- a/packages/tailwindcss/src/candidate.ts +++ b/packages/tailwindcss/src/candidate.ts @@ -438,6 +438,9 @@ export function* parseCandidate(input: string, designSystem: DesignSystem): Iter let valueIsArbitrary = startArbitraryIdx !== -1 if (valueIsArbitrary) { + // Arbitrary values must end with a `]`. + if (value[value.length - 1] !== ']') return + let arbitraryValue = decodeArbitraryValue(value.slice(startArbitraryIdx + 1, -1)) // Extract an explicit typehint if present, e.g. `bg-[color:var(--my-var)])` From f6e97032164a1586dc8daaad2468d2a457c2d2da Mon Sep 17 00:00:00 2001 From: Robin Malfait Date: Sun, 29 Dec 2024 01:39:32 +0100 Subject: [PATCH 3/3] update changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index df9331a4b8ad..fc12e8684858 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Don’t detect arbitrary properties when preceded by an escape ([#15456](https://github.com/tailwindlabs/tailwindcss/pull/15456)) - 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)) - Fix `inset-shadow-*` suggestions in IntelliSense ([#15471](https://github.com/tailwindlabs/tailwindcss/pull/15471)) +- Only compile arbitrary values ending in `]` ([#15503](https://github.com/tailwindlabs/tailwindcss/pull/15503)) ### Changed