Skip to content
This repository has been archived by the owner on Apr 21, 2023. It is now read-only.

Commit

Permalink
height:0% should not be minified to height:0
Browse files Browse the repository at this point in the history
Fixes #1261
  • Loading branch information
jmarantz committed Feb 11, 2016
1 parent 60f8018 commit 7c30b7e
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
2 changes: 1 addition & 1 deletion net/instaweb/rewriter/css_filter_test.cc
Expand Up @@ -1042,7 +1042,7 @@ TEST_F(CssFilterTest, ComplexCssTest) {
"}\n"
".foo { color: rgba(1, 2, 3, 0.4); }\n",

"body{background-image:-webkit-gradient(linear,50% 0,50% 100%,"
"body{background-image:-webkit-gradient(linear,50% 0%,50% 100%,"
"from(#e8edf0),to(#fcfcfd));color:red}.foo{color:rgba(1,2,3,.4)}" },

// Counters
Expand Down
8 changes: 6 additions & 2 deletions net/instaweb/rewriter/css_minify.cc
Expand Up @@ -356,8 +356,12 @@ bool IsLength(const GoogleString& unit) {

bool UnitsRequiredForValueZero(const GoogleString& unit) {
// https://github.com/pagespeed/mod_pagespeed/issues/1164 : Chrome does not
// allow abbreviating 0s as 0. It only allows that abbreviation for lengths.
return !IsLength(unit) && (unit != "%");
// allow abbreviating 0s or 0% as 0. It only allows that abbreviation for
// lengths.
//
// https://github.com/pagespeed/mod_pagespeed/issues/1261 See
// https://www.w3.org/TR/CSS2/visudet.html#the-height-property
return (unit == "%") || !IsLength(unit);
}

} // namespace
Expand Down
5 changes: 3 additions & 2 deletions net/instaweb/rewriter/css_minify_test.cc
Expand Up @@ -133,10 +133,11 @@ TEST_F(CssMinifyTest, DoNotFixBadColorsOrUnits) {
minified);
}

TEST_F(CssMinifyTest, RemoveZeroLengthButNotTimeSuffix) {
TEST_F(CssMinifyTest, RemoveZeroLengthButNotTimeOrPercentSuffix) {
const char kCss[] =
".a {\n"
" width: 0px;\n"
" height: 0%;\n"
" -moz-transition-delay: 0s, 0s;\n"
"}";
GoogleString minified;
Expand All @@ -145,7 +146,7 @@ TEST_F(CssMinifyTest, RemoveZeroLengthButNotTimeSuffix) {
EXPECT_TRUE(minify.ParseStylesheet(kCss));
// TODO(jmarantz): this CSS is not well minified. We should strip
// the spaces around the comma.
EXPECT_STREQ(".a{width:0;-moz-transition-delay:0s , 0s}", minified);
EXPECT_STREQ(".a{width:0;height:0%;-moz-transition-delay:0s , 0s}", minified);
}

} // namespace
Expand Down

0 comments on commit 7c30b7e

Please sign in to comment.