Skip to content

Commit a4d1bdb

Browse files
authored
Fix angle brackets in content (#5585)
* move to real regexes These regexes are only calculated once so we don't really have a performance penalty here. However, it's a bit nicer to do it this way because now you don't have to think about the proper escapes. /.*/.source will basically take the source of the regex ".*" without flags and converts it to a string with the proper escapes for you. Fun fact, this `.source` property has been supported since Chrome, Firefox and Safari version 1. * allow for `'>'` in `content-['>']`
1 parent 77d1243 commit a4d1bdb

File tree

3 files changed

+8
-4
lines changed

3 files changed

+8
-4
lines changed

src/lib/expandTailwindAtRules.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ let env = sharedState.env
77
let contentMatchCache = sharedState.contentMatchCache
88

99
const PATTERNS = [
10-
"([^<>\"'`\\s]*\\['[^<>\"'`\\s]*'\\])", // `content-['hello']` but not `content-['hello']']`
11-
'([^<>"\'`\\s]*\\["[^<>"\'`\\s]*"\\])', // `content-["hello"]` but not `content-["hello"]"]`
12-
'([^<>"\'`\\s]*\\[[^<>"\'`\\s]+\\])', // `fill-[#bada55]`
13-
'([^<>"\'`\\s]*[^<>"\'`\\s:])', // `px-1.5`, `uppercase` but not `uppercase:`
10+
/([^<>"'`\s]*\['[^"'`\s]*'\])/.source, // `content-['hello']` but not `content-['hello']']`
11+
/([^<>"'`\s]*\["[^"'`\s]*"\])/.source, // `content-["hello"]` but not `content-["hello"]"]`
12+
/([^<>"'`\s]*\[[^"'`\s]+\])/.source, // `fill-[#bada55]`
13+
/([^<>"'`\s]*[^"'`\s:])/.source, // `px-1.5`, `uppercase` but not `uppercase:`].join('|')
1414
].join('|')
1515
const BROAD_MATCH_GLOBAL_REGEXP = new RegExp(PATTERNS, 'g')
1616
const INNER_MATCH_GLOBAL_REGEXP = /[^<>"'`\s.(){}[\]#=%]*[^<>"'`\s.(){}[\]#=%:]/g

tests/arbitrary-values.test.css

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -477,6 +477,9 @@
477477
.content-\[attr\(content-before\)\] {
478478
content: attr(content-before);
479479
}
480+
.content-\[\'\>\'\] {
481+
content: '>';
482+
}
480483
@media (min-width: 1024px) {
481484
.lg\:grid-cols-\[200px\2c repeat\(auto-fill\2c minmax\(15\%\2c 100px\)\)\2c 300px\] {
482485
grid-template-columns: 200px repeat(auto-fill, minmax(15%, 100px)) 300px;

tests/arbitrary-values.test.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@
132132
<div class="will-change-[top,left] will-change-[var(--will-change)]"></div>
133133
<div class="content-['hello']"></div>
134134
<div class="content-[attr(content-before)]"></div>
135+
<div class="content-['>']"></div>
135136
<div class="accent-[#bada55]"></div>
136137
<div class="accent-[var(--accent-color)]"></div>
137138

0 commit comments

Comments
 (0)