Fixes #311 - exception with leading/trailing decimal point.
authorJonathan-L <Jonathan-L@users.noreply.github.com>
Thu, 3 Jul 2014 11:52:45 +0000 (12:52 +0100)
committerJakub Pawlowicz <contact@jakubpawlowicz.com>
Fri, 4 Jul 2014 21:01:53 +0000 (22:01 +0100)
History.md
lib/clean.js
test/unit-test.js

index fca2ce8..bfebc2c 100644 (file)
@@ -1,3 +1,8 @@
+[2.2.6 / 2014-xx-xx](https://github.com/GoalSmashers/clean-css/compare/v2.2.5...v2.2.6)
+==================
+
+* Fixed issue [#311](https://github.com/GoalSmashers/clean-css/issues/311) - leading/trailing decimal points.
+
 [2.2.5 / 2014-06-29](https://github.com/GoalSmashers/clean-css/compare/v2.2.4...v2.2.5)
 ==================
 
index d5d4168..f5c1128 100644 (file)
@@ -272,7 +272,10 @@ var minify = function(data, callback) {
   });
 
   // .0 to 0
-  replace(/(\D)\.0+(,|\}|\))/g, '$10$2');
+  // repeated twice on purpose as if not it doesn't process {padding: .0 .0 .0 .0} correctly
+  var leadingDecimalRegexp = /(\D)\.0+(\D)/g;
+  replace(leadingDecimalRegexp, '$10$2');
+  replace(leadingDecimalRegexp, '$10$2');
 
   // fraction zeros removal
   replace(/\.([1-9]*)0+(\D)/g, function(match, nonZeroPart, suffix) {
@@ -285,7 +288,7 @@ var minify = function(data, callback) {
     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('(\\s|:|,)\\-?(\\d+)\\.(\\D)', 'g'), '$1$2$3');
   replace(new RegExp('rect\\(0(?:' + units.join('|') + ')', 'g'), 'rect(0');
 
   // restore % in rgb/rgba and hsl/hsla
index 84fd2a1..2dd4a23 100644 (file)
@@ -434,6 +434,14 @@ vows.describe('clean-units').addBatch({
       'body{margin:.0}',
       'body{margin:0}'
     ],
+    'zero as .0 #3': [
+      'body{margin:.0em}',
+      'body{margin:0}'
+    ],
+    'zero as .0 #4': [
+      'body{margin:.0 1em .0 .0}',
+      'body{margin:0 1em 0 0}'
+    ],
     'missing #1': [
       'body{margin:2.em}',
       'body{margin:2em}'
@@ -442,6 +450,10 @@ vows.describe('clean-units').addBatch({
       'p{opacity:1.}',
       'p{opacity:1}'
     ],
+    'missing #3': [
+      'p{opacity:11.px}',
+      'p{opacity:11px}'
+    ],
     'minus zero as value to zero': [
       'body{margin:-0}',
       'body{margin:0}'