Skip to content

Commit

Permalink
Fixes #945 - hex RGBA colors in IE filters.
Browse files Browse the repository at this point in the history
Why:

* MS filters support hex RGBA colors and we were not matching correctly
  against them.
  • Loading branch information
jakubpawlowicz committed Jun 28, 2017
1 parent 7bd604d commit 2161d39
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 3 deletions.
5 changes: 5 additions & 0 deletions History.md
@@ -1,3 +1,8 @@
[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)
==================

Expand Down
6 changes: 3 additions & 3 deletions lib/optimizer/level-1/optimize.js
Expand Up @@ -98,11 +98,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) {
Expand Down
16 changes: 16 additions & 0 deletions test/optimizer/level-1/optimize-test.js
Expand Up @@ -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 })
)
Expand All @@ -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': [
Expand Down

0 comments on commit 2161d39

Please sign in to comment.