Skip to content

Commit 399440e

Browse files
Don't output unparsable values (#6469)
1 parent 4b2482f commit 399440e

File tree

3 files changed

+70
-1
lines changed

3 files changed

+70
-1
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1111

1212
- Warn about invalid globs in `content` ([#6449](https://github.com/tailwindlabs/tailwindcss/pull/6449))
1313

14+
### Fixed
15+
16+
- Don't output unparsable values ([#6469](https://github.com/tailwindlabs/tailwindcss/pull/6469))
17+
1418
## [3.0.2] - 2021-12-13
1519

1620
### Fixed

src/lib/generateRules.js

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,16 +248,39 @@ function parseRules(rule, cache, options = {}) {
248248
return [cache.get(rule), options]
249249
}
250250

251+
const IS_VALID_PROPERTY_NAME = /^[a-z_-]/
252+
253+
function isValidPropName(name) {
254+
return IS_VALID_PROPERTY_NAME.test(name)
255+
}
256+
257+
function isParsableCssValue(property, value) {
258+
try {
259+
postcss.parse(`a{${property}:${value}}`).toResult()
260+
return true
261+
} catch (err) {
262+
return false
263+
}
264+
}
265+
251266
function extractArbitraryProperty(classCandidate, context) {
252267
let [, property, value] = classCandidate.match(/^\[([a-zA-Z0-9-_]+):(\S+)\]$/) ?? []
253268

254269
if (value === undefined) {
255270
return null
256271
}
257272

273+
if (!isValidPropName(property)) {
274+
return null
275+
}
276+
277+
if (!isValidArbitraryValue(value)) {
278+
return null
279+
}
280+
258281
let normalized = normalize(value)
259282

260-
if (!isValidArbitraryValue(normalized)) {
283+
if (!isParsableCssValue(property, normalized)) {
261284
return null
262285
}
263286

tests/arbitrary-properties.test.js

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,3 +231,45 @@ test('invalid class', () => {
231231
expect(result.css).toMatchFormattedCss(css``)
232232
})
233233
})
234+
235+
test('invalid arbitrary property', () => {
236+
let config = {
237+
content: [
238+
{
239+
raw: html`<div class="[autoplay:\${autoplay}]"></div>`,
240+
},
241+
],
242+
corePlugins: { preflight: false },
243+
}
244+
245+
let input = css`
246+
@tailwind base;
247+
@tailwind components;
248+
@tailwind utilities;
249+
`
250+
251+
return run(input, config).then((result) => {
252+
expect(result.css).toMatchFormattedCss(css``)
253+
})
254+
})
255+
256+
test('invalid arbitrary property 2', () => {
257+
let config = {
258+
content: [
259+
{
260+
raw: html`[0:02]`,
261+
},
262+
],
263+
corePlugins: { preflight: false },
264+
}
265+
266+
let input = css`
267+
@tailwind base;
268+
@tailwind components;
269+
@tailwind utilities;
270+
`
271+
272+
return run(input, config).then((result) => {
273+
expect(result.css).toMatchFormattedCss(css``)
274+
})
275+
})

0 commit comments

Comments
 (0)