Fixes #562 - optimizing invalid color values.
authorJakub Pawlowicz <contact@jakubpawlowicz.com>
Wed, 20 May 2015 20:39:50 +0000 (21:39 +0100)
committerJakub Pawlowicz <contact@jakubpawlowicz.com>
Wed, 20 May 2015 20:39:50 +0000 (21:39 +0100)
We'll leave them as is for now as it's too tricky to remove them
at this point.

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

index e174d7d..bf67f5c 100644 (file)
@@ -12,6 +12,7 @@
 * Fixed issue [#448](https://github.com/jakubpawlowicz/clean-css/issues/448) - rebasing no protocol URIs.
 * Fixed issue [#517](https://github.com/jakubpawlowicz/clean-css/issues/517) - turning off color optimizations.
 * Fixed issue [#542](https://github.com/jakubpawlowicz/clean-css/issues/542) - space after closing brace in IE.
+* Fixed issue [#562](https://github.com/jakubpawlowicz/clean-css/issues/562) - optimizing invalid color values.
 * Fixed issue [#563](https://github.com/jakubpawlowicz/clean-css/issues/563) - `background:inherit` restoring.
 * Fixed issue [#570](https://github.com/jakubpawlowicz/clean-css/issues/570) - rebasing "no-url()" imports.
 * Fixed issue [#574](https://github.com/jakubpawlowicz/clean-css/issues/574) - rewriting internal URLs.
index 6582d83..9ad66a1 100644 (file)
@@ -144,7 +144,10 @@ function colorMininifier(_, value, compatibility) {
     })
     .replace(/(rgb|rgba|hsl|hsla)\(([^\)]+)\)/g, function(match, colorFunction, colorDef) {
       var tokens = colorDef.split(',');
-      var applies = colorFunction == 'hsl' || colorFunction == 'hsla' || tokens[0].indexOf('%') > -1;
+      var applies = (colorFunction == 'hsl' && tokens.length == 3) ||
+        (colorFunction == 'hsla' && tokens.length == 4) ||
+        (colorFunction == 'rgb' && tokens.length == 3 && colorDef.indexOf('%') > 0) ||
+        (colorFunction == 'rgba' && tokens.length == 4 && colorDef.indexOf('%') > 0);
       if (!applies)
         return match;
 
index 55e6610..76bfdc7 100644 (file)
@@ -237,6 +237,14 @@ vows.describe(SimpleOptimizer)
       'partial name as a suffix': [
         'a{font-family:alrightsanslp-black}',
         [['font-family', 'alrightsanslp-black']]
+      ],
+      'invalid rgba declaration - color': [
+        'a{color:rgba(255 0 0)}',
+        [['color', 'rgba(255 0 0)']]
+      ],
+      'invalid rgba declaration - background': [
+        'a{background:rgba(255 0 0)}',
+        [['background', 'rgba(255 0 0)']]
       ]
     })
   )