Skip to content

Commit

Permalink
ensure we can use "special" characters in modifiers
Browse files Browse the repository at this point in the history
Fixes: #6778
  • Loading branch information
RobinMalfait committed Jan 3, 2022
1 parent 875c850 commit 36a236f
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/lib/defaultExtractor.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ const PATTERNS = [
/([^<>"'`\s]*\[[^<>"'`\s]*:'[^"'`\s]*'\])/.source, // `[content:'hello']` but not `[content:"hello"]`
/([^<>"'`\s]*\[[^<>"'`\s]*:"[^"'`\s]*"\])/.source, // `[content:"hello"]` but not `[content:'hello']`
/([^<>"'`\s]*\[[^"'`\s]+\][^<>"'`\s]*)/.source, // `fill-[#bada55]`, `fill-[#bada55]/50`
/([^"'`\s]*[^<>"'`\s:\\])/.source, // `<sm:underline`, `md>:font-bold`
/([^<>"'`\s]*[^"'`\s:\\])/.source, // `px-1.5`, `uppercase` but not `uppercase:`

// Arbitrary properties
Expand Down
9 changes: 9 additions & 0 deletions tests/default-extractor.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -323,3 +323,12 @@ test('arbitrary values with angle brackets in double quotes', async () => {
expect(extractions).toContain(`hover:content-["<"]`)
expect(extractions).toContain(`hover:focus:content-[">"]`)
})

test('special characters', async () => {
const extractions = defaultExtractor(`
<div class="<sm:underline md>:font-bold"></div>
`)

expect(extractions).toContain(`<sm:underline`)
expect(extractions).toContain(`md>:font-bold`)
})
22 changes: 22 additions & 0 deletions tests/variants.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -445,3 +445,25 @@ it('should not generate variants of user css if it is not inside a layer', () =>
`)
})
})

it('should be possible to use responsive modifiers that are defined with special characters', () => {
let config = {
content: [{ raw: html`<div class="<sm:underline"></div>` }],
theme: {
screens: {
'<sm': { max: '399px' },
},
},
plugins: [],
}

return run('@tailwind utilities', config).then((result) => {
return expect(result.css).toMatchFormattedCss(css`
@media (max-width: 399px) {
.\<sm\:underline {
text-decoration-line: underline;
}
}
`)
})
})

0 comments on commit 36a236f

Please sign in to comment.