From: Jakub Pawlowicz Date: Wed, 5 Feb 2014 07:14:02 +0000 (+0000) Subject: Fixes #230 - adds better handling of zero values. X-Git-Url: https://git.ndcode.org/public/gitweb.cgi?a=commitdiff_plain;h=c3e4bb319dbb3231b6961c07b64720c8107cfc04;p=clean-css.git Fixes #230 - adds better handling of zero values. Previously 0.0 + unit and -0 was handled incorrectly. --- diff --git a/History.md b/History.md index cc3dc5a6..170d30d0 100644 --- a/History.md +++ b/History.md @@ -18,6 +18,7 @@ * Fixed issue [#218](https://github.com/GoalSmashers/clean-css/issues/218) - `@import` statements cleanup. * Fixed issue [#220](https://github.com/GoalSmashers/clean-css/issues/220) - selector between comments. * Fixed issue [#229](https://github.com/GoalSmashers/clean-css/issues/229) - improved processing of fraction numbers. +* Fixed issue [#230](https://github.com/GoalSmashers/clean-css/issues/230) - better handling of zero values. [2.0.7 / 2014-01-16](https://github.com/GoalSmashers/clean-css/compare/v2.0.6...v2.0.7) ================== diff --git a/lib/clean.js b/lib/clean.js index f4c21753..60e82aa4 100644 --- a/lib/clean.js +++ b/lib/clean.js @@ -259,14 +259,9 @@ var minify = function(data, callback) { return match; }); - // zero + unit to zero - var units = ['px', 'em', 'ex', 'cm', 'mm', 'in', 'pt', 'pc', '%']; - if ('ie8' != options.compatibility) - units.push('rem'); - - replace(new RegExp('(\\s|:|,)0(?:' + units.join('|') + ')', 'g'), '$1' + '0'); - replace(new RegExp('(\\s|:|,)(\\d)\\.(\\D)', 'g'), '$1$2$3'); - replace(new RegExp('rect\\(0(?:' + units.join('|') + ')', 'g'), 'rect(0'); + // minus zero to zero + replace(/(\s|:|,|\()\-0([^\.])/g, '$10$2'); + replace(/-0([,\)])/g, '0$1'); // zero(s) + value to value replace(/(\s|:|,)0+([1-9])/g, '$1$2'); @@ -284,6 +279,15 @@ var minify = function(data, callback) { return (nonZeroPart.length > 0 ? '.' : '') + nonZeroPart + suffix; }); + // zero + unit to zero + var units = ['px', 'em', 'ex', 'cm', 'mm', 'in', 'pt', 'pc', '%']; + if ('ie8' != options.compatibility) + units.push('rem'); + + replace(new RegExp('(\\s|:|,)\\-?0(?:' + units.join('|') + ')', 'g'), '$1' + '0'); + replace(new RegExp('(\\s|:|,)\\-?(\\d)\\.(\\D)', 'g'), '$1$2$3'); + replace(new RegExp('rect\\(0(?:' + units.join('|') + ')', 'g'), 'rect(0'); + // restore % in rgb/rgba and hsl/hsla replace(/(rgb|rgba|hsl|hsla)\(([^\)]+)\)/g, function(match, colorFunction, colorDef) { var tokens = colorDef.split(','); diff --git a/test/data/big-min.css b/test/data/big-min.css index 26d3140f..e4d2aa3b 100644 --- a/test/data/big-min.css +++ b/test/data/big-min.css @@ -1263,7 +1263,7 @@ label i{font-style:normal;display:none} #bandeau_bas a{color:#fff} #bandeau_bas .conteneur_lives{position:relative;z-index:2} .conteneur_lives .lives{position:absolute;bottom:0;right:0;color:#fff} -#bandeau_bas .conteneur_lives .lives{-webkit-box-shadow:-3px 4px 15px -0 rgba(0,11,21,.5);-moz-box-shadow:-3px 4px 15px -0 rgba(0,11,21,.5);box-shadow:-3px 4px 15px -0 rgba(0,11,21,.5)} +#bandeau_bas .conteneur_lives .lives{-webkit-box-shadow:-3px 4px 15px 0 rgba(0,11,21,.5);-moz-box-shadow:-3px 4px 15px 0 rgba(0,11,21,.5);box-shadow:-3px 4px 15px 0 rgba(0,11,21,.5)} .conteneur_lives.popuped .lives{position:relative} .conteneur_lives .live{width:328px;right:0;background-color:#F6F6F6} .conteneur_lives .live .bandeau{height:25px;width:320px;padding-right:8px;overflow:hidden;line-height:23px;cursor:pointer;background-color:#f5f5f5;background-image:-moz-linear-gradient(top,#d20303,#bf0202);background-image:-ms-linear-gradient(top,#d20303,#bf0202);background-image:-webkit-gradient(linear,0 0,0 100%,from(#d20303),to(#bf0202));background-image:-webkit-linear-gradient(top,#d20303,#bf0202);background-image:-o-linear-gradient(top,#d20303,#bf0202);background-image:linear-gradient(top,#d20303,#bf0202);background-repeat:repeat-x;filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#d20303', endColorstr='#bf0202', GradientType=0)} @@ -2982,4 +2982,4 @@ html.js body.dummy div#mainContent div#core-liberation div.col9 div.block div.bl html.js body.dummy div#mainContent div#core-liberation div.col9 div.block div.block-content div.favorites-frontpages div.col-left div.cartridge{width:388px} html.js body.dummy div#mainContent div#core-liberation div.col9 div.block div.block-content div.favorites-folders div.block-call-items div.block-content div.mini-tpl div.cartridge{margin-left:0;width:129px} html.js body.dummy div#mainContent div#core-liberation div.col7 div.block-call-items div.block-content div.mini-tpl div.folder-on-demand div.object-content{margin-right:0;min-height:0;border-bottom:0} -html.js body.dummy div#mainContent div#core-liberation div.col7 div.block-call-items div.block-content div.mini-tpl div.folder-on-demand{border-bottom:1px solid #E7E7E7} \ No newline at end of file +html.js body.dummy div#mainContent div#core-liberation div.col7 div.block-call-items div.block-content div.mini-tpl div.folder-on-demand{border-bottom:1px solid #E7E7E7} diff --git a/test/unit-test.js b/test/unit-test.js index ec9a4771..4de87681 100644 --- a/test/unit-test.js +++ b/test/unit-test.js @@ -432,6 +432,22 @@ vows.describe('clean-units').addBatch({ 'missing #2': [ 'p{opacity:1.}', 'p{opacity:1}' + ], + 'minus zero as value to zero': [ + 'body{margin:-0}', + 'body{margin:0}' + ], + 'minus zero in function to zero': [ + 'body{color:rgba(-0,-0,-0,-0)}', + 'body{color:rgba(0,0,0,0)}' + ], + 'minus zero px to zero': [ + 'body{margin:-0px}', + 'body{margin:0}' + ], + 'zero em to zero': [ + 'body{margin:0.0em}', + 'body{margin:0}' ] }), 'zero values in ie8 compatibility mode': cssContext({