Skip to content
This repository was archived by the owner on Apr 10, 2025. It is now read-only.

Commit 7c30b7e

Browse files
committed
height:0% should not be minified to height:0
Fixes #1261
1 parent 60f8018 commit 7c30b7e

3 files changed

Lines changed: 10 additions & 5 deletions

File tree

‎net/instaweb/rewriter/css_filter_test.cc‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1042,7 +1042,7 @@ TEST_F(CssFilterTest, ComplexCssTest) {
10421042
"}\n"
10431043
".foo { color: rgba(1, 2, 3, 0.4); }\n",
10441044

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

10481048
// Counters

‎net/instaweb/rewriter/css_minify.cc‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -356,8 +356,12 @@ bool IsLength(const GoogleString& unit) {
356356

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

363367
} // namespace

‎net/instaweb/rewriter/css_minify_test.cc‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,10 +133,11 @@ TEST_F(CssMinifyTest, DoNotFixBadColorsOrUnits) {
133133
minified);
134134
}
135135

136-
TEST_F(CssMinifyTest, RemoveZeroLengthButNotTimeSuffix) {
136+
TEST_F(CssMinifyTest, RemoveZeroLengthButNotTimeOrPercentSuffix) {
137137
const char kCss[] =
138138
".a {\n"
139139
" width: 0px;\n"
140+
" height: 0%;\n"
140141
" -moz-transition-delay: 0s, 0s;\n"
141142
"}";
142143
GoogleString minified;
@@ -145,7 +146,7 @@ TEST_F(CssMinifyTest, RemoveZeroLengthButNotTimeSuffix) {
145146
EXPECT_TRUE(minify.ParseStylesheet(kCss));
146147
// TODO(jmarantz): this CSS is not well minified. We should strip
147148
// the spaces around the comma.
148-
EXPECT_STREQ(".a{width:0;-moz-transition-delay:0s , 0s}", minified);
149+
EXPECT_STREQ(".a{width:0;height:0%;-moz-transition-delay:0s , 0s}", minified);
149150
}
150151

151152
} // namespace

0 commit comments

Comments
 (0)