Skip to content

Commit a5f4644

Browse files
Validate named values in candidate parser (#19397)
Fixes tailwindlabs/tailwindcss-intellisense#1506
1 parent 5f107e2 commit a5f4644

File tree

3 files changed

+14
-1
lines changed

3 files changed

+14
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
2020
- Improve backwards compatibility for `content` theme key from JS configs ([#19381](https://github.com/tailwindlabs/tailwindcss/pull/19381))
2121
- Upgrade: Handle `future` and `experimental` config keys ([#19344](https://github.com/tailwindlabs/tailwindcss/pull/19344))
2222
- Try to canonicalize any arbitrary utility to a bare value ([#19379](https://github.com/tailwindlabs/tailwindcss/pull/19379))
23+
- Validate candidates similarly to Oxide ([#19397](https://github.com/tailwindlabs/tailwindcss/pull/19397))
2324
- Canonicalization: combine `text-*` and `leading-*` classes ([#19396](https://github.com/tailwindlabs/tailwindcss/pull/19396))
2425

2526
### Added

packages/tailwindcss/src/candidate.test.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1997,7 +1997,12 @@ it.each([
19971997

19981998
// Arbitrary variant values that end the block
19991999
'data-[a]{color:red}foo[a]:flex',
2000-
])('should not parse invalid arbitrary values: %s', (rawCandidate) => {
2000+
2001+
// Named values contain invalid characters
2002+
'data-foo=bar:flex',
2003+
'bg-foo=bar',
2004+
'bg-red-500/foo=bar',
2005+
])('should not parse invalid values: %s', (rawCandidate) => {
20012006
let utilities = new Utilities()
20022007
utilities.static('flex', () => [])
20032008
utilities.functional('bg', () => [])

packages/tailwindcss/src/candidate.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ const COLON = 0x3a
1010
const DASH = 0x2d
1111
const LOWER_A = 0x61
1212
const LOWER_Z = 0x7a
13+
const IS_VALID_NAMED_VALUE = /^[a-zA-Z0-9_.%-]+$/
1314

1415
export type ArbitraryUtilityValue = {
1516
kind: 'arbitrary'
@@ -596,6 +597,8 @@ export function* parseCandidate(input: string, designSystem: DesignSystem): Iter
596597
? null
597598
: `${value}/${modifierSegment}`
598599

600+
if (!IS_VALID_NAMED_VALUE.test(value)) continue
601+
599602
candidate.value = {
600603
kind: 'named',
601604
value,
@@ -647,6 +650,8 @@ function parseModifier(modifier: string): CandidateModifier | null {
647650
}
648651
}
649652

653+
if (!IS_VALID_NAMED_VALUE.test(modifier)) return null
654+
650655
return {
651656
kind: 'named',
652657
value: modifier,
@@ -798,6 +803,8 @@ export function parseVariant(variant: string, designSystem: DesignSystem): Varia
798803
}
799804
}
800805

806+
if (!IS_VALID_NAMED_VALUE.test(value)) continue
807+
801808
return {
802809
kind: 'functional',
803810
root,

0 commit comments

Comments
 (0)