Skip to content

Commit ec259be

Browse files
Fixes #986 - CSS 4 colors in level 2 optimizations.
1 parent 8f52600 commit ec259be

3 files changed

Lines changed: 19 additions & 3 deletions

File tree

History.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
* Fixed issue [#861](https://github.com/jakubpawlowicz/clean-css/issues/861) - new `transition` property optimizer.
66
* Fixed issue [#895](https://github.com/jakubpawlowicz/clean-css/issues/895) - ignoring specific styles.
77
* Fixed issue [#947](https://github.com/jakubpawlowicz/clean-css/issues/947) - selector based filtering.
8+
* Fixed issue [#986](https://github.com/jakubpawlowicz/clean-css/issues/986) - level 2 optimizations and CSS 4 colors.
89
* Fixed issue [#1038](https://github.com/jakubpawlowicz/clean-css/issues/1038) - `font-variation-settings` quoting.
910
* Fixes ReDOS vulnerabilities in validator code.
1011

lib/optimizer/validator.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,19 @@ var decimalRegex = /[0-9]/;
88
var functionAnyRegex = new RegExp('^' + functionAnyRegexStr + '$', 'i');
99
var hslColorRegex = /^hsl\(\s{0,31}[\-\.]?\d+\s{0,31},\s{0,31}\.?\d+%\s{0,31},\s{0,31}\.?\d+%\s{0,31}\)|hsla\(\s{0,31}[\-\.]?\d+\s{0,31},\s{0,31}\.?\d+%\s{0,31},\s{0,31}\.?\d+%\s{0,31},\s{0,31}\.?\d+\s{0,31}\)$/;
1010
var identifierRegex = /^(\-[a-z0-9_][a-z0-9\-_]*|[a-z][a-z0-9\-_]*)$/i;
11-
var longHexColorRegex = /^#[0-9a-f]{6}$/i;
1211
var namedEntityRegex = /^[a-z]+$/i;
1312
var prefixRegex = /^-([a-z0-9]|-)*$/i;
1413
var rgbColorRegex = /^rgb\(\s{0,31}[\d]{1,3}\s{0,31},\s{0,31}[\d]{1,3}\s{0,31},\s{0,31}[\d]{1,3}\s{0,31}\)|rgba\(\s{0,31}[\d]{1,3}\s{0,31},\s{0,31}[\d]{1,3}\s{0,31},\s{0,31}[\d]{1,3}\s{0,31},\s{0,31}[\.\d]+\s{0,31}\)$/;
15-
var shortHexColorRegex = /^#[0-9a-f]{3}$/i;
1614
var timingFunctionRegex = /^(cubic\-bezier|steps)\([^\)]+\)$/;
1715
var validTimeUnits = ['ms', 's'];
1816
var urlRegex = /^url\([\s\S]+\)$/i;
1917
var variableRegex = new RegExp('^' + variableRegexStr + '$', 'i');
2018

19+
var eightValueColorRegex = /^#[0-9a-f]{8}$/i;
20+
var fourValueColorRegex = /^#[0-9a-f]{4}$/i;
21+
var sixValueColorRegex = /^#[0-9a-f]{6}$/i;
22+
var threeValueColorRegex = /^#[0-9a-f]{3}$/i;
23+
2124
var DECIMAL_DOT = '.';
2225
var MINUS_SIGN = '-';
2326
var PLUS_SIGN = '+';
@@ -365,7 +368,7 @@ function isFunction(value) {
365368
}
366369

367370
function isHexColor(value) {
368-
return shortHexColorRegex.test(value) || longHexColorRegex.test(value);
371+
return threeValueColorRegex.test(value) || fourValueColorRegex.test(value) || sixValueColorRegex.test(value) || eightValueColorRegex.test(value);
369372
}
370373

371374
function isHslColor(value) {

test/optimizer/level-2/optimize-test.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,18 @@ vows.describe('level 2 optimizer')
106106
]
107107
}, { level: 2 })
108108
)
109+
.addBatch(
110+
optimizerContext('colors', {
111+
'four value colors': [
112+
'.block{border:1px solid #0001}',
113+
'.block{border:1px solid #0001}'
114+
],
115+
'eight value colors': [
116+
'.block{border:1px solid #00000001}',
117+
'.block{border:1px solid #00000001}'
118+
]
119+
}, { level: 2 })
120+
)
109121
.addBatch(
110122
optimizerContext('unit merging', {
111123
'font-size': [

0 commit comments

Comments
 (0)