From: Jakub Pawlowicz Date: Sun, 16 Aug 2015 15:43:07 +0000 (+0100) Subject: Fixes #635 - adds safer `0%` optimizations. X-Git-Url: https://git.ndcode.org/public/gitweb.cgi?a=commitdiff_plain;h=58064a6f555651b30aec3bd41dff9ed4b1a7e37d;p=clean-css.git Fixes #635 - adds safer `0%` optimizations. Apparently we can't turn `0%` into `0` for height & max-height where layout breaks, see: http://codepen.io/H1D/pen/bdzRJo --- diff --git a/History.md b/History.md index 25c3c37e..fff1111b 100644 --- a/History.md +++ b/History.md @@ -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. diff --git a/lib/selectors/simple.js b/lib/selectors/simple.js index 0737d6af..203cd102 100644 --- a/lib/selectors/simple.js +++ b/lib/selectors/simple.js @@ -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'); diff --git a/test/selectors/simple-test.js b/test/selectors/simple-test.js index d228e00c..79bf7647 100644 --- a/test/selectors/simple-test.js +++ b/test/selectors/simple-test.js @@ -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%']] ] }) )