Skip to content

Commit

Permalink
Do not serialize unitless zero lengths in custom properties
Browse files Browse the repository at this point in the history
  • Loading branch information
devongovett committed Nov 30, 2022
1 parent 8911365 commit 0afccf9
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
11 changes: 9 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6717,8 +6717,14 @@ mod tests {
);
minify_test("@media { .foo { color: chartreuse }}", ".foo{color:#7fff00}");
minify_test("@media all { .foo { color: chartreuse }}", ".foo{color:#7fff00}");
minify_test("@media not (((color) or (hover))) { .foo { color: chartreuse }}", "@media not ((color) or (hover)){.foo{color:#7fff00}}");
minify_test("@media (hover) and ((color) and (test)) { .foo { color: chartreuse }}", "@media (hover) and (color) and (test){.foo{color:#7fff00}}");
minify_test(
"@media not (((color) or (hover))) { .foo { color: chartreuse }}",
"@media not ((color) or (hover)){.foo{color:#7fff00}}",
);
minify_test(
"@media (hover) and ((color) and (test)) { .foo { color: chartreuse }}",
"@media (hover) and (color) and (test){.foo{color:#7fff00}}",
);

prefix_test(
r#"
Expand Down Expand Up @@ -17835,6 +17841,7 @@ mod tests {
);
minify_test(".foo { --test: .5s; }", ".foo{--test:.5s}");
minify_test(".foo { --theme-sizes-1\\/12: 2 }", ".foo{--theme-sizes-1\\/12:2}");
minify_test(".foo { --test: 0px; }", ".foo{--test:0px}");

prefix_test(
r#"
Expand Down
4 changes: 3 additions & 1 deletion src/properties/custom.rs
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,9 @@ impl<'i> TokenList<'i> {
self.write_whitespace_if_needed(i, dest)?
}
TokenOrValue::Length(v) => {
v.to_css(dest)?;
// Do not serialize unitless zero lengths in custom properties as it may break calc().
let (value, unit) = v.to_unit_value();
serialize_dimension(value, unit, dest)?;
false
}
TokenOrValue::Angle(v) => {
Expand Down

0 comments on commit 0afccf9

Please sign in to comment.