Skip to content

Commit 913d72c

Browse files
Fixes #1008 - edge case in breaking up font.
`font` shorthand needs `font-size` and `font-family`.
1 parent bedd8a9 commit 913d72c

File tree

3 files changed

+66
-2
lines changed

3 files changed

+66
-2
lines changed

History.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
* Fixed issue [#988](https://github.com/jakubpawlowicz/clean-css/issues/988) - edge case in dropping default animation-duration.
55
* Fixed issue [#989](https://github.com/jakubpawlowicz/clean-css/issues/989) - edge case in removing unused at rules.
66
* Fixed issue [#1001](https://github.com/jakubpawlowicz/clean-css/issues/1001) - corrupted tokenizer state.
7+
* Fixed issue [#1008](https://github.com/jakubpawlowicz/clean-css/issues/1008) - edge case in breaking up `font` shorthand.
78

89
[4.1.9 / 2017-09-19](https://github.com/jakubpawlowicz/clean-css/compare/v4.1.8...v4.1.9)
910
==================

lib/optimizer/level-2/break-up.js

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,10 @@ function font(property, compactable, validator) {
299299
return components;
300300
}
301301

302+
if (values.length < 2 || !_anyIsFontSize(values, validator) || !_anyIsFontFamily(values, validator)) {
303+
throw new InvalidPropertyError('Invalid font values at ' + formatPosition(property.all[property.position][1][2][0]) + '. Ignoring.');
304+
}
305+
302306
if (values.length > 1 && _anyIsInherit(values)) {
303307
throw new InvalidPropertyError('Invalid font values at ' + formatPosition(values[0][2][0]) + '. Ignoring.');
304308
}
@@ -377,6 +381,36 @@ function font(property, compactable, validator) {
377381
return components;
378382
}
379383

384+
function _anyIsFontSize(values, validator) {
385+
var value;
386+
var i, l;
387+
388+
for (i = 0, l = values.length; i < l; i++) {
389+
value = values[i];
390+
391+
if (validator.isFontSizeKeyword(value[1]) || validator.isUnit(value[1]) && !validator.isDynamicUnit(value[1]) || validator.isFunction(value[1])) {
392+
return true;
393+
}
394+
}
395+
396+
return false;
397+
}
398+
399+
function _anyIsFontFamily(values, validator) {
400+
var value;
401+
var i, l;
402+
403+
for (i = 0, l = values.length; i < l; i++) {
404+
value = values[i];
405+
406+
if (validator.isIdentifier(value[1])) {
407+
return true;
408+
}
409+
}
410+
411+
return false;
412+
}
413+
380414
function fourValues(property, compactable) {
381415
var componentNames = compactable[property.name].components;
382416
var components = [];

test/optimizer/level-2/break-up-test.js

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1302,8 +1302,8 @@ vows.describe(breakUp)
13021302
return _breakUp([
13031303
[
13041304
'property',
1305-
['property-name', 'font'],
1306-
['property-value', 'italic', [[0, 13, undefined]]],
1305+
['property-name', 'font', [[0, 13, undefined]]],
1306+
['property-value', 'italic'],
13071307
['property-value', 'sans-serif']
13081308
]
13091309
]);
@@ -1528,6 +1528,35 @@ vows.describe(breakUp)
15281528
assert.deepEqual(components[6].value, [['property-value', '-clean-css-icon']]);
15291529
}
15301530
},
1531+
'normal as font': {
1532+
'topic': function () {
1533+
return _breakUp([
1534+
[
1535+
'property',
1536+
['property-name', 'font', [[0, 6, undefined]]],
1537+
['property-value', 'normal']
1538+
]
1539+
]);
1540+
},
1541+
'has 0 components': function (components) {
1542+
assert.lengthOf(components, 0);
1543+
}
1544+
},
1545+
'non-identifier as font family': {
1546+
'topic': function () {
1547+
return _breakUp([
1548+
[
1549+
'property',
1550+
['property-name', 'font', [[0, 6, undefined]]],
1551+
['property-value', '16px'],
1552+
['property-value', '123']
1553+
]
1554+
]);
1555+
},
1556+
'has 0 components': function (components) {
1557+
assert.lengthOf(components, 0);
1558+
}
1559+
},
15311560
'unset font': {
15321561
'topic': function () {
15331562
return _breakUp([

0 commit comments

Comments
 (0)