Skip to content

Commit a2196b0

Browse files
Escape animation names when prefixes contain special characters (#11470)
* Escape animation names when prefixes contain special characters * Update changelog
1 parent eae2b7a commit a2196b0

File tree

3 files changed

+32
-1
lines changed

3 files changed

+32
-1
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1717
- Fix source maps issue resulting in a crash ([#11319](https://github.com/tailwindlabs/tailwindcss/pull/11319))
1818
- Fallback to RegEx based parser when using custom transformers or extractors ([#11335](https://github.com/tailwindlabs/tailwindcss/pull/11335))
1919
- Move unknown pseudo-elements outside of `:is` by default ([#11345](https://github.com/tailwindlabs/tailwindcss/pull/11345))
20+
- Escape animation names when prefixes contain special characters ([#11470](https://github.com/tailwindlabs/tailwindcss/pull/11470))
2021

2122
### Added
2223

src/corePlugins.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -933,7 +933,7 @@ export let corePlugins = {
933933
},
934934

935935
animation: ({ matchUtilities, theme, config }) => {
936-
let prefixName = (name) => `${config('prefix')}${escapeClassName(name)}`
936+
let prefixName = (name) => escapeClassName(config('prefix') + name)
937937
let keyframes = Object.fromEntries(
938938
Object.entries(theme('keyframes') ?? {}).map(([key, value]) => {
939939
return [key, { [`@keyframes ${prefixName(key)}`]: value }]

tests/animations.test.js

+30
Original file line numberDiff line numberDiff line change
@@ -277,3 +277,33 @@ test('with dots in the name and prefix', () => {
277277
`)
278278
})
279279
})
280+
281+
test('special character prefixes are escaped in animation names', () => {
282+
let config = {
283+
prefix: '@',
284+
content: [{ raw: `<div class="@animate-one"></div>` }],
285+
theme: {
286+
extend: {
287+
keyframes: {
288+
one: { to: { transform: 'rotate(360deg)' } },
289+
},
290+
animation: {
291+
one: 'one 2s',
292+
},
293+
},
294+
},
295+
}
296+
297+
return run('@tailwind utilities', config).then((result) => {
298+
expect(result.css).toMatchFormattedCss(css`
299+
@keyframes \@one {
300+
to {
301+
transform: rotate(360deg);
302+
}
303+
}
304+
.\@animate-one {
305+
animation: 2s \@one;
306+
}
307+
`)
308+
})
309+
})

0 commit comments

Comments
 (0)