Skip to content

Commit

Permalink
fix(preset-mini): don't extract non-quoted colon character (#2361)
Browse files Browse the repository at this point in the history
  • Loading branch information
sibbng committed Mar 17, 2023
1 parent be07365 commit 69787ef
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 4 deletions.
4 changes: 2 additions & 2 deletions packages/core/src/extractors/split.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import { isValidSelector } from '../utils'

const defaultSplitRE = /\\?[\s'"`;{}]+/g
export const quotedArbitraryValuesRE = /(?:[\w&:[\]-]|\[\S+=\S+\])+\[\\?['"]?\S+?['"]\]\]?[\w:-]*/g
export const arbitraryPropertyRE = /\[(\\\W|[\w-])+:['"]?\S+?['"]?\]/g
const arbitraryPropertyCandidateRE = new RegExp(`^${arbitraryPropertyRE.source}$`)
export const arbitraryPropertyRE = /\[(\\\W|[\w-])+:[^\s:]*?("\S+?"|'\S+?'|`\S+?`|[^\s:]+?)[^\s:]*?\)?\]/g
const arbitraryPropertyCandidateRE = /^\[(\\\W|[\w-])+:['"]?\S+?['"]?\]$/

export const splitCode = (code: string) => {
const result = new Set<string>()
Expand Down
2 changes: 1 addition & 1 deletion packages/preset-mini/src/_rules/variables.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export const cssVariables: Rule[] = [
]

export const cssProperty: Rule[] = [
[/^\[(--(\w|\\\W)+|[\w-]+):([^:].*)\]$/, ([match, prop,, value]) => {
[/^\[(--(\w|\\\W)+|[\w-]+):([^\s:]*?("\S+?"|'\S+?'|`\S+?`|[^\s:]+?)[^\s:]*?\)?)\]$/, ([match, prop,, value]) => {
if (!isURI(match.slice(1, -1)))
return { [prop]: h.bracket(`[${value}]`) }
}],
Expand Down
1 change: 1 addition & 0 deletions test/assets/preset-mini-targets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1102,6 +1102,7 @@ export const presetMiniNonTargets = [
'["update:modelValue"]',
'[https://en.wikipedia.org/wiki]',
'[Baz::class]',
'[foo:bar:baz]',
// escaped arbitrary css properties only allowed in css variables
'[cant\~escape:me]',

Expand Down
1 change: 1 addition & 0 deletions test/extractor.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ it('extractorSplit', async () => {
expect(await extract('<div class="text-red border">foo</div>')).toContain('text-red')
expect(await extract('<div class="<sm:text-lg">foo</div>')).toContain('<sm:text-lg')
expect(await extract('"class=\"bg-white\""')).toContain('bg-white')
expect((await extract('<div class="[content:\'bar:baz\'] [foo:bar:baz]">')).includes('[foo:bar:baz]')).toBeFalsy()
})

it('extractorSvelte uses regular split with non .svelte files', async () => {
Expand Down
7 changes: 6 additions & 1 deletion test/pos.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ describe('matched-positions', async () => {
],
})

expect(await match(uno, '<div class="[color:red] [color:\'red\']"></div>'))
expect(await match(uno, '<div class="[color:red] [color:\'red\'] [foo:bar:baz] [content:\'bar:baz\']"></div>'))
.toMatchInlineSnapshot(`
[
[
Expand All @@ -177,6 +177,11 @@ describe('matched-positions', async () => {
37,
"[color:'red']",
],
[
52,
71,
"[content:'bar:baz']",
],
]
`)
})
Expand Down

0 comments on commit 69787ef

Please sign in to comment.