Fixes #945 - hex RGBA colors in IE filters.
authorJakub Pawlowicz <contact@jakubpawlowicz.com>
Wed, 28 Jun 2017 12:31:07 +0000 (14:31 +0200)
committerJakub Pawlowicz <contact@jakubpawlowicz.com>
Thu, 29 Jun 2017 06:53:01 +0000 (08:53 +0200)
Why:

* IE filters support hex RGBA colors and we were not matching correctly
  against them.

History.md
lib/optimizer/level-1/optimize.js
test/optimizer/level-1/optimize-test.js

index f095351..0cb34ca 100644 (file)
@@ -6,6 +6,11 @@
 * Fixed issue [#895](https://github.com/jakubpawlowicz/clean-css/issues/895) - ignoring specific styles.
 * Fixed issue [#947](https://github.com/jakubpawlowicz/clean-css/issues/947) - selector based filtering.
 
+[4.1.5 / 2017-xx-xx](https://github.com/jakubpawlowicz/clean-css/compare/v4.1.4...4.1)
+==================
+
+* Fixed issue [#945](https://github.com/jakubpawlowicz/clean-css/issues/945) - hex RGBA colors in IE filters.
+
 [4.1.4 / 2017-06-14](https://github.com/jakubpawlowicz/clean-css/compare/v4.1.3...v4.1.4)
 ==================
 
index 56f2f60..1cec591 100644 (file)
@@ -100,11 +100,11 @@ function optimizeColors(name, value, compatibility) {
     .replace(/hsl\((-?\d+),(-?\d+)%?,(-?\d+)%?\)/g, function (match, hue, saturation, lightness) {
       return shortenHsl(hue, saturation, lightness);
     })
-    .replace(/(^|[^='"])#([0-9a-f]{6})/gi, function (match, prefix, color) {
+    .replace(/(^|[^='"])#([0-9a-f]{6})($|[^0-9a-f])/gi, function (match, prefix, color, suffix) {
       if (color[0] == color[1] && color[2] == color[3] && color[4] == color[5]) {
-        return (prefix + '#' + color[0] + color[2] + color[4]).toLowerCase();
+        return (prefix + '#' + color[0] + color[2] + color[4]).toLowerCase() + suffix;
       } else {
-        return (prefix + '#' + color).toLowerCase();
+        return (prefix + '#' + color).toLowerCase() + suffix;
       }
     })
     .replace(/(^|[^='"])#([0-9a-f]{3})/gi, function (match, prefix, color) {
index 89885cb..ac8ce88 100644 (file)
@@ -392,6 +392,14 @@ vows.describe('level 1 optimizations')
       'uppercase hex to lowercase hex': [
         'a{color:#FFF}',
         'a{color:#fff}'
+      ],
+      '4-value hex': [
+        '.block{color:#0f0a}',
+        '.block{color:#0f0a}'
+      ],
+      '8-value hex': [
+        '.block{color:#00ff0080}',
+        '.block{color:#00ff0080}'
       ]
     }, { level: 1 })
   )
@@ -415,6 +423,14 @@ vows.describe('level 1 optimizations')
       ]
     }, { level: 1, compatibility: 'ie8' })
   )
+  .addBatch(
+    optimizerContext('colors - ie7 compatibility', {
+      '8-value hex in gradient': [
+        '.block{filter:progid:DXImageTransform.Microsoft.gradient(gradientType=0, startColorstr= #66000000, endColorstr= #66000000)}',
+        '.block{filter:progid:DXImageTransform.Microsoft.gradient(gradientType=0, startColorstr=#66000000, endColorstr=#66000000)}'
+      ]
+    }, { level: 1, compatibility: 'ie7' })
+  )
   .addBatch(
     optimizerContext('colors - no optimizations', {
       'long hex into short': [