Skip to content

Commit 69787ef

Browse files
authored
fix(preset-mini): don't extract non-quoted colon character (unocss#2361)
1 parent be07365 commit 69787ef

File tree

5 files changed

+11
-4
lines changed

5 files changed

+11
-4
lines changed

packages/core/src/extractors/split.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ import { isValidSelector } from '../utils'
33

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

99
export const splitCode = (code: string) => {
1010
const result = new Set<string>()

packages/preset-mini/src/_rules/variables.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ export const cssVariables: Rule[] = [
2626
]
2727

2828
export const cssProperty: Rule[] = [
29-
[/^\[(--(\w|\\\W)+|[\w-]+):([^:].*)\]$/, ([match, prop,, value]) => {
29+
[/^\[(--(\w|\\\W)+|[\w-]+):([^\s:]*?("\S+?"|'\S+?'|`\S+?`|[^\s:]+?)[^\s:]*?\)?)\]$/, ([match, prop,, value]) => {
3030
if (!isURI(match.slice(1, -1)))
3131
return { [prop]: h.bracket(`[${value}]`) }
3232
}],

test/assets/preset-mini-targets.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1102,6 +1102,7 @@ export const presetMiniNonTargets = [
11021102
'["update:modelValue"]',
11031103
'[https://en.wikipedia.org/wiki]',
11041104
'[Baz::class]',
1105+
'[foo:bar:baz]',
11051106
// escaped arbitrary css properties only allowed in css variables
11061107
'[cant\~escape:me]',
11071108

test/extractor.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ it('extractorSplit', async () => {
1010
expect(await extract('<div class="text-red border">foo</div>')).toContain('text-red')
1111
expect(await extract('<div class="<sm:text-lg">foo</div>')).toContain('<sm:text-lg')
1212
expect(await extract('"class=\"bg-white\""')).toContain('bg-white')
13+
expect((await extract('<div class="[content:\'bar:baz\'] [foo:bar:baz]">')).includes('[foo:bar:baz]')).toBeFalsy()
1314
})
1415

1516
it('extractorSvelte uses regular split with non .svelte files', async () => {

test/pos.test.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ describe('matched-positions', async () => {
164164
],
165165
})
166166

167-
expect(await match(uno, '<div class="[color:red] [color:\'red\']"></div>'))
167+
expect(await match(uno, '<div class="[color:red] [color:\'red\'] [foo:bar:baz] [content:\'bar:baz\']"></div>'))
168168
.toMatchInlineSnapshot(`
169169
[
170170
[
@@ -177,6 +177,11 @@ describe('matched-positions', async () => {
177177
37,
178178
"[color:'red']",
179179
],
180+
[
181+
52,
182+
71,
183+
"[content:'bar:baz']",
184+
],
180185
]
181186
`)
182187
})

0 commit comments

Comments
 (0)