Skip to content

Commit 0afccf9

Browse files
committed
Do not serialize unitless zero lengths in custom properties
1 parent 8911365 commit 0afccf9

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

src/lib.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6717,8 +6717,14 @@ mod tests {
67176717
);
67186718
minify_test("@media { .foo { color: chartreuse }}", ".foo{color:#7fff00}");
67196719
minify_test("@media all { .foo { color: chartreuse }}", ".foo{color:#7fff00}");
6720-
minify_test("@media not (((color) or (hover))) { .foo { color: chartreuse }}", "@media not ((color) or (hover)){.foo{color:#7fff00}}");
6721-
minify_test("@media (hover) and ((color) and (test)) { .foo { color: chartreuse }}", "@media (hover) and (color) and (test){.foo{color:#7fff00}}");
6720+
minify_test(
6721+
"@media not (((color) or (hover))) { .foo { color: chartreuse }}",
6722+
"@media not ((color) or (hover)){.foo{color:#7fff00}}",
6723+
);
6724+
minify_test(
6725+
"@media (hover) and ((color) and (test)) { .foo { color: chartreuse }}",
6726+
"@media (hover) and (color) and (test){.foo{color:#7fff00}}",
6727+
);
67226728

67236729
prefix_test(
67246730
r#"
@@ -17835,6 +17841,7 @@ mod tests {
1783517841
);
1783617842
minify_test(".foo { --test: .5s; }", ".foo{--test:.5s}");
1783717843
minify_test(".foo { --theme-sizes-1\\/12: 2 }", ".foo{--theme-sizes-1\\/12:2}");
17844+
minify_test(".foo { --test: 0px; }", ".foo{--test:0px}");
1783817845

1783917846
prefix_test(
1784017847
r#"

src/properties/custom.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -360,7 +360,9 @@ impl<'i> TokenList<'i> {
360360
self.write_whitespace_if_needed(i, dest)?
361361
}
362362
TokenOrValue::Length(v) => {
363-
v.to_css(dest)?;
363+
// Do not serialize unitless zero lengths in custom properties as it may break calc().
364+
let (value, unit) = v.to_unit_value();
365+
serialize_dimension(value, unit, dest)?;
364366
false
365367
}
366368
TokenOrValue::Angle(v) => {

0 commit comments

Comments
 (0)