Fixes #230 - adds better handling of zero values.
authorJakub Pawlowicz <jakub@goalsmashers.com>
Wed, 5 Feb 2014 07:14:02 +0000 (07:14 +0000)
committerJakub Pawlowicz <jakub@goalsmashers.com>
Wed, 5 Feb 2014 07:14:49 +0000 (07:14 +0000)
Previously 0.0 + unit and -0 was handled incorrectly.

History.md
lib/clean.js
test/data/big-min.css
test/unit-test.js

index cc3dc5a..170d30d 100644 (file)
@@ -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)
 ==================
index f4c2175..60e82aa 100644 (file)
@@ -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(',');
index 26d3140..e4d2aa3 100644 (file)
@@ -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}
index ec9a477..4de8768 100644 (file)
@@ -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({