Fixes #499 - too aggressive `-` removal.
authorJakub Pawlowicz <contact@jakubpawlowicz.com>
Tue, 17 Mar 2015 20:13:36 +0000 (20:13 +0000)
committerJakub Pawlowicz <contact@jakubpawlowicz.com>
Tue, 17 Mar 2015 20:36:43 +0000 (20:36 +0000)
So far we don't check if a stripped value is a numerical one so
we should be extra careful about removing such values.

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

index 3b82120..88552e4 100644 (file)
@@ -12,6 +12,7 @@
 [3.1.8 / 2015-xx-xx](https://github.com/jakubpawlowicz/clean-css/compare/v3.1.7...3.1)
 ==================
 
+* Fixes issue [#499](https://github.com/jakubpawlowicz/clean-css/issues/499) - too aggressive `-` removal.
 * Fixes issue [#498](https://github.com/jakubpawlowicz/clean-css/issues/498) - reordering and flexbox.
 
 [3.1.7 / 2015-03-16](https://github.com/jakubpawlowicz/clean-css/compare/v3.1.6...v3.1.7)
index a9bd64d..028dbc6 100644 (file)
@@ -89,9 +89,13 @@ function zeroMinifier(_, value) {
   if (value.indexOf('0') == -1)
     return value;
 
+  if (value.indexOf('-') > -1) {
+    value = value
+      .replace(/([^\w\d\-]|^)\-0([^\.]|$)/g, '$10$2')
+      .replace(/([^\w\d\-]|^)\-0([^\.]|$)/g, '$10$2');
+  }
+
   return value
-    .replace(/\-0$/g, '0')
-    .replace(/\-0([^\.])/g, '0$1')
     .replace(/(^|\s)0+([1-9])/g, '$1$2')
     .replace(/(^|\D)\.0+(\D|$)/g, '$10$2')
     .replace(/(^|\D)\.0+(\D|$)/g, '$10$2')
index 268d378..b7f03b8 100644 (file)
@@ -441,6 +441,10 @@ vows.describe(SimpleOptimizer)
         'a{margin:-0px}',
         ['margin:0']
       ],
+      '-0% to 0': [
+        'a{width:-0%}',
+        ['width:0']
+      ],
       'missing': [
         'a{opacity:1.}',
         ['opacity:1']
@@ -453,6 +457,18 @@ vows.describe(SimpleOptimizer)
         'a{margin:-0.5em}',
         ['margin:-.5em']
       ],
+      'inside names #1': [
+        'div{animation-name:test-0-bounce}',
+        ['animation-name:test-0-bounce']
+      ],
+      'inside names #2': [
+        'div{animation-name:test-0bounce}',
+        ['animation-name:test-0bounce']
+      ],
+      'inside names #3': [
+        'div{animation-name:test-0px}',
+        ['animation-name:test-0px']
+      ],
       'strips leading from value': [
         'a{padding:010px 0015px}',
         ['padding:10px 15px']