Ensure invalid typehints are not generated (#5590)

This commit is contained in:
Robin Malfait 2021-09-24 18:18:48 +02:00 • committed by GitHub
parent abcd9acd18
commit 79b37a874c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 24 additions and 2 deletions

View file

@ -284,8 +284,12 @@ let typeMap = {
lookup: asLookupValue,
}
let supportedTypes = Object.keys(typeMap)
function splitAtFirst(input, delim) {
return (([first, ...rest]) => [first, rest.join(delim)])(input.split(delim))
let idx = input.indexOf(delim)
if (idx === -1) return [undefined, input]
return [input.slice(0, idx), input.slice(idx + 1)]
}
export function coerceValue(type, modifier, values, tailwindConfig) {
@ -294,7 +298,11 @@ export function coerceValue(type, modifier, values, tailwindConfig) {
if (isArbitraryValue(modifier)) {
let [explicitType, value] = splitAtFirst(modifier.slice(1, -1), ':')
if (value.length > 0 && Object.keys(typeMap).includes(explicitType)) {
if (explicitType !== undefined && !supportedTypes.includes(explicitType)) {
return []
}
if (value.length > 0 && supportedTypes.includes(explicitType)) {
return [asValue(`[${value}]`, values, tailwindConfig), explicitType]
}

View file

@ -16,6 +16,20 @@ test('arbitrary values', () => {
})
})
it('should not generate any css if an unknown typehint is used', () => {
let config = {
content: [
{
raw: html`<div class="inset-[hmm:12px]"></div>`,
},
],
}
return run('@tailwind utilities', config).then((result) => {
return expect(result.css).toMatchFormattedCss(css``)
})
})
it('should convert _ to spaces', () => {
let config = {
content: [