Skip to content

Commit

Permalink
Fixes #1106 - regression in handling RGBA and HSLA colors.
Browse files Browse the repository at this point in the history
  • Loading branch information
jakubpawlowicz committed Jan 28, 2020
1 parent a75f942 commit f47397c
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 1 deletion.
5 changes: 5 additions & 0 deletions History.md
@@ -1,3 +1,8 @@
[4.2.3 / 2020-xx-xx](https://github.com/jakubpawlowicz/clean-css/compare/v4.2.2...4.2)
==================

* Fixed issue [#1106](https://github.com/jakubpawlowicz/clean-css/issues/1106) - regression in handling RGBA/HSLA colors.

[4.2.2 / 2020-01-25](https://github.com/jakubpawlowicz/clean-css/compare/v4.2.1...v4.2.2)
==================

Expand Down
2 changes: 1 addition & 1 deletion lib/optimizer/level-1/optimize.js
Expand Up @@ -106,7 +106,7 @@ function optimizeColors(name, value, compatibility) {
}

value = value
.replace(/(rgb|hsl)a?\((\-?\d+),(\-?\d+\%?),(\-?\d+\%?),(0*[1-9]+[0-9]*(.?\d*)?)\)/gi, function (match, colorFn, p1, p2, p3, alpha) {
.replace(/(rgb|hsl)a?\((\-?\d+),(\-?\d+\%?),(\-?\d+\%?),(0*[1-9]+[0-9]*(\.?\d*)?)\)/gi, function (match, colorFn, p1, p2, p3, alpha) {
return (parseInt(alpha, 10) >= 1 ? colorFn + '(' + [p1,p2,p3].join(',') + ')' : match);
})
.replace(/rgb\((\-?\d+),(\-?\d+),(\-?\d+)\)/gi, function (match, red, green, blue) {
Expand Down
4 changes: 4 additions & 0 deletions test/optimizer/level-1/optimize-test.js
Expand Up @@ -412,6 +412,10 @@ vows.describe('level 1 optimizations')
'8-value hex': [
'.block{color:#00ff0080}',
'.block{color:#00ff0080}'
],
'rgba inside a function': [
'.block{background-image:linear-gradient(to right,rgba(255,255,255,0),rgba(255,255,255,1))}',
'.block{background-image:linear-gradient(to right,rgba(255,255,255,0),#fff)}'
]
}, { level: 1 })
)
Expand Down

0 comments on commit f47397c

Please sign in to comment.