Skip to content

Commit b857d80

Browse files
authored
Ensure that we test every value for the length datatype (#6283)
* ensure that we test every value for the `length` datatype * update changelog
1 parent e2d5f21 commit b857d80

File tree

4 files changed

+12
-5
lines changed

4 files changed

+12
-5
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
2424
- Add CSS functions to data types ([#6258](https://github.com/tailwindlabs/tailwindcss/pull/6258))
2525
- Add CSS functions to data types ([#6258](https://github.com/tailwindlabs/tailwindcss/pull/6258))
2626
- Support negative values for `scale-*` utilities ([c48e629](https://github.com/tailwindlabs/tailwindcss/commit/c48e629955585ad18dadba9f470fda59cc448ab7))
27+
- Improve `length` data type, by validating each value individually ([#6283](https://github.com/tailwindlabs/tailwindcss/pull/6283))
2728

2829
### Changed
2930

src/util/dataTypes.js

+7-5
Original file line numberDiff line numberDiff line change
@@ -80,11 +80,13 @@ let lengthUnits = [
8080
]
8181
let lengthUnitsPattern = `(?:${lengthUnits.join('|')})`
8282
export function length(value) {
83-
return (
84-
value === '0' ||
85-
new RegExp(`${lengthUnitsPattern}$`).test(value) ||
86-
cssFunctions.some((fn) => new RegExp(`^${fn}\\(.+?${lengthUnitsPattern}`).test(value))
87-
)
83+
return value.split(UNDERSCORE).every((part) => {
84+
return (
85+
part === '0' ||
86+
new RegExp(`${lengthUnitsPattern}$`).test(part) ||
87+
cssFunctions.some((fn) => new RegExp(`^${fn}\\(.+?${lengthUnitsPattern}`).test(part))
88+
)
89+
})
8890
}
8991

9092
let lineWidths = new Set(['thin', 'medium', 'thick'])

tests/arbitrary-values.test.css

+3
Original file line numberDiff line numberDiff line change
@@ -666,6 +666,9 @@
666666
.bg-\[length\:var\(--value\)\] {
667667
background-size: var(--value);
668668
}
669+
.bg-\[center_top_1rem\] {
670+
background-position: center top 1rem;
671+
}
669672
.bg-\[position\:200px_100px\] {
670673
background-position: 200px 100px;
671674
}

tests/arbitrary-values.test.html

+1
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,7 @@
236236
<div class="bg-[length:200px_100px]"></div>
237237
<div class="bg-[length:var(--value)]"></div>
238238

239+
<div class="bg-[center_top_1rem]"></div>
239240
<div class="bg-[position:200px_100px]"></div>
240241
<div class="bg-[position:var(--value)]"></div>
241242

0 commit comments

Comments
 (0)