Fixes #635 - adds safer `0%` optimizations.
authorJakub Pawlowicz <contact@jakubpawlowicz.com>
Sun, 16 Aug 2015 15:43:07 +0000 (16:43 +0100)
committerJakub Pawlowicz <contact@jakubpawlowicz.com>
Sun, 16 Aug 2015 15:51:43 +0000 (16:51 +0100)
Apparently we can't turn `0%` into `0` for height & max-height where
layout breaks, see: http://codepen.io/H1D/pen/bdzRJo

History.md
lib/selectors/simple.js
test/selectors/simple-test.js

index 25c3c37..fff1111 100644 (file)
@@ -8,6 +8,7 @@
 * Fixed issue [#612](https://github.com/jakubpawlowicz/clean-css/issues/612) - adds HTTP proxy support.
 * Fixed issue [#618](https://github.com/jakubpawlowicz/clean-css/issues/618) - adds safer function validation.
 * Fixed issue [#625](https://github.com/jakubpawlowicz/clean-css/issues/625) - adds length unit optimizations.
+* Fixed issue [#635](https://github.com/jakubpawlowicz/clean-css/issues/635) - adds safer `0%` optimizations.
 * Fixed issue [#644](https://github.com/jakubpawlowicz/clean-css/issues/644) - adds time unit optimizations.
 * Fixed issue [#645](https://github.com/jakubpawlowicz/clean-css/issues/645) - adds bottom to top `media` merging.
 * Fixed issue [#648](https://github.com/jakubpawlowicz/clean-css/issues/648) - adds property level at-rule support.
index 0737d6a..203cd10 100644 (file)
@@ -103,6 +103,9 @@ function unitMinifier(name, value, unitsRegexp) {
   if (name == 'flex' || name == '-ms-flex' || name == '-webkit-flex' || name == 'flex-basis' || name == '-webkit-flex-basis')
     return value;
 
+  if (value.indexOf('%') > 0 && (name == 'height' || name == 'max-height'))
+    return value;
+
   return value
     .replace(unitsRegexp, '$1' + '0' + '$2')
     .replace(unitsRegexp, '$1' + '0' + '$2');
index d228e00..79bf764 100644 (file)
@@ -625,6 +625,18 @@ vows.describe('simple optimizations')
       'rect zeros with commas': [
         'a{clip:rect(0px, 0px, 0px, 0px)}',
         [['clip', 'rect(0,0,0,0)']]
+      ],
+      'height': [
+        'a{height:0%}',
+        [['height', '0%']]
+      ],
+      'min-height': [
+        'a{min-height:0%}',
+        [['min-height', '0']]
+      ],
+      'max-height': [
+        'a{max-height:0%}',
+        [['max-height', '0%']]
       ]
     })
   )