Skip to content

Commit

Permalink
fix: certain inputs causing regex matching to hang (#3500)
Browse files Browse the repository at this point in the history
  • Loading branch information
lewisl9029 committed Jan 17, 2024
1 parent 901db34 commit a361d77
Show file tree
Hide file tree
Showing 3 changed files with 543 additions and 3 deletions.
9 changes: 6 additions & 3 deletions packages/extractor-arbitrary-variants/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@ import type { Extractor } from '@unocss/core'
import { defaultSplitRE, isValidSelector } from '@unocss/core'
import { removeSourceMap } from './source-map'

export const quotedArbitraryValuesRE = /(?:[\w&:[\]-]|\[\S+=\S+\])+\[\\?['"]?\S+?['"]\]\]?[\w:-]*/g
export const arbitraryPropertyRE = /\[(\\\W|[\w-])+:[^\s:]*?("\S+?"|'\S+?'|`\S+?`|[^\s:]+?)[^\s:]*?\)?\]/g
const arbitraryPropertyCandidateRE = /^\[(\\\W|[\w-])+:['"]?\S+?['"]?\]$/
export const quotedArbitraryValuesRE
= /(?:[\w&:[\]-]|\[\S{1,64}=\S{1,64}\]){1,64}\[\\?['"]?\S{1,64}?['"]\]\]?[\w:-]{0,64}/g
export const arbitraryPropertyRE
= /\[(\\\W|[\w-]){1,64}:[^\s:]{0,64}?("\S{1,64}?"|'\S{1,64}?'|`\S{1,64}?`|[^\s:]{1,64}?)[^\s:]{0,64}?\)?\]/g
const arbitraryPropertyCandidateRE
= /^\[(\\\W|[\w-]){1,64}:['"]?\S{1,64}?['"]?\]$/

export function splitCodeWithArbitraryVariants(code: string): string[] {
const result: string[] = []
Expand Down

0 comments on commit a361d77

Please sign in to comment.