Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Match arbitrary properties even when followed by square bracketed text #10212

Merged
merged 2 commits into from
Jan 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Properly handle subtraction followed by a variable ([#10074](https://github.com/tailwindlabs/tailwindcss/pull/10074))
- Fix missing `string[]` in the `theme.dropShadow` types ([#10072](https://github.com/tailwindlabs/tailwindcss/pull/10072))
- Update list of length units ([#10100](https://github.com/tailwindlabs/tailwindcss/pull/10100))
- Fix not matching arbitrary properties when closely followed by square brackets ([#10212](https://github.com/tailwindlabs/tailwindcss/pull/10212))

### Changed

Expand Down
10 changes: 8 additions & 2 deletions src/lib/defaultExtractor.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,14 @@ function* buildRegExps(context) {
: ''

let utility = regex.any([
// Arbitrary properties
/\[[^\s:'"`]+:[^\s]+\]/,
// Arbitrary properties (without square brackets)
/\[[^\s:'"`]+:[^\s\[\]]+\]/,

// Arbitrary properties with balanced square brackets
// This is a targeted fix to continue to allow theme()
// with square brackets to work in arbitrary properties
// while fixing a problem with the regex matching too much
/\[[^\s:'"`]+:[^\s]+?\[[^\s]+?\][^\s]+?\]/,

// Utilities
regex.pattern([
Expand Down
8 changes: 8 additions & 0 deletions tests/default-extractor.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -488,3 +488,11 @@ test('ruby percent string array', () => {

expect(extractions).toContain(`text-[#bada55]`)
})

test('arbitrary properties followed by square bracketed stuff', () => {
let extractions = defaultExtractor(
'<div class="h-16 items-end border border-white [display:inherit]">[foo]</div>'
)

expect(extractions).toContain(`[display:inherit]`)
})