11import type { DesignSystem } from './design-system'
22import { decodeArbitraryValue } from './utils/decode-arbitrary-value'
3+ import { isValidArbitrary } from './utils/is-valid-arbitrary'
34import { segment } from './utils/segment'
45
56const COLON = 0x3a
@@ -326,6 +327,9 @@ export function* parseCandidate(input: string, designSystem: DesignSystem): Iter
326327 let property = baseWithoutModifier . slice ( 0 , idx )
327328 let value = decodeArbitraryValue ( baseWithoutModifier . slice ( idx + 1 ) )
328329
330+ // Values can't contain `;` or ` }` characters at the top-level.
331+ if ( ! isValidArbitrary ( value ) ) return
332+
329333 yield {
330334 kind : 'arbitrary' ,
331335 property,
@@ -443,6 +447,9 @@ export function* parseCandidate(input: string, designSystem: DesignSystem): Iter
443447
444448 let arbitraryValue = decodeArbitraryValue ( value . slice ( startArbitraryIdx + 1 , - 1 ) )
445449
450+ // Values can't contain `;` or ` }` characters at the top-level.
451+ if ( ! isValidArbitrary ( arbitraryValue ) ) continue
452+
446453 // Extract an explicit typehint if present, e.g. `bg-[color:var(--my-var)])`
447454 let typehint = ''
448455 for ( let i = 0 ; i < arbitraryValue . length ; i ++ ) {
@@ -500,6 +507,9 @@ function parseModifier(modifier: string): CandidateModifier | null {
500507 if ( modifier [ 0 ] === '[' && modifier [ modifier . length - 1 ] === ']' ) {
501508 let arbitraryValue = decodeArbitraryValue ( modifier . slice ( 1 , - 1 ) )
502509
510+ // Values can't contain `;` or ` }` characters at the top-level.
511+ if ( ! isValidArbitrary ( arbitraryValue ) ) return null
512+
503513 // Empty arbitrary values are invalid. E.g.: `data-[]:`
504514 // ^^
505515 if ( arbitraryValue . length === 0 || arbitraryValue . trim ( ) . length === 0 ) return null
@@ -513,6 +523,9 @@ function parseModifier(modifier: string): CandidateModifier | null {
513523 if ( modifier [ 0 ] === '(' && modifier [ modifier . length - 1 ] === ')' ) {
514524 let arbitraryValue = decodeArbitraryValue ( modifier . slice ( 1 , - 1 ) )
515525
526+ // Values can't contain `;` or ` }` characters at the top-level.
527+ if ( ! isValidArbitrary ( arbitraryValue ) ) return null
528+
516529 // Empty arbitrary values are invalid. E.g.: `data-():`
517530 // ^^
518531 if ( arbitraryValue . length === 0 || arbitraryValue . trim ( ) . length === 0 ) return null
@@ -552,6 +565,9 @@ export function parseVariant(variant: string, designSystem: DesignSystem): Varia
552565
553566 let selector = decodeArbitraryValue ( variant . slice ( 1 , - 1 ) )
554567
568+ // Values can't contain `;` or ` }` characters at the top-level.
569+ if ( ! isValidArbitrary ( selector ) ) return null
570+
555571 // Empty arbitrary values are invalid. E.g.: `[]:`
556572 // ^^
557573 if ( selector . length === 0 || selector . trim ( ) . length === 0 ) return null
@@ -629,6 +645,9 @@ export function parseVariant(variant: string, designSystem: DesignSystem): Varia
629645
630646 let arbitraryValue = decodeArbitraryValue ( value . slice ( 1 , - 1 ) )
631647
648+ // Values can't contain `;` or ` }` characters at the top-level.
649+ if ( ! isValidArbitrary ( arbitraryValue ) ) return null
650+
632651 // Empty arbitrary values are invalid. E.g.: `data-[]:`
633652 // ^^
634653 if ( arbitraryValue . length === 0 || arbitraryValue . trim ( ) . length === 0 ) return null
@@ -650,6 +669,9 @@ export function parseVariant(variant: string, designSystem: DesignSystem): Varia
650669
651670 let arbitraryValue = decodeArbitraryValue ( value . slice ( 1 , - 1 ) )
652671
672+ // Values can't contain `;` or ` }` characters at the top-level.
673+ if ( ! isValidArbitrary ( arbitraryValue ) ) return null
674+
653675 // Empty arbitrary values are invalid. E.g.: `data-():`
654676 // ^^
655677 if ( arbitraryValue . length === 0 || arbitraryValue . trim ( ) . length === 0 ) return null
0 commit comments