Skip to content

Commit

Permalink
Fix local fonts with colors in name (#1077)
Browse files Browse the repository at this point in the history
* fix(optimizer): do not convert colors inside local font names
  • Loading branch information
Sirius-A authored and jakubpawlowicz committed Sep 17, 2019
1 parent dc728a8 commit 3b2d0d2
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
7 changes: 6 additions & 1 deletion lib/optimizer/level-1/optimize.js
Expand Up @@ -37,8 +37,13 @@ var IMPORT_PREFIX_PATTERN = /^@import/i;
var QUOTED_PATTERN = /^('.*'|".*")$/;
var QUOTED_BUT_SAFE_PATTERN = /^['"][a-zA-Z][a-zA-Z\d\-_]+['"]$/;
var URL_PREFIX_PATTERN = /^url\(/i;
var LOCAL_PREFIX_PATTERN = /^local\(/i;
var VARIABLE_NAME_PATTERN = /^--\S+$/;

function isLocal(value){
return LOCAL_PREFIX_PATTERN.test(value);
}

function isNegative(value) {
return value && value[1][0] == '-' && parseFloat(value[1]) < 0;
}
Expand Down Expand Up @@ -443,7 +448,7 @@ function optimizeBody(rule, properties, context) {
value = !options.compatibility.properties.urlQuotes ?
removeUrlQuotes(value) :
value;
} else if (isQuoted(value)) {
} else if (isQuoted(value) || isLocal(value)) {
value = levelOptions.removeQuotes ?
removeQuotes(name, value) :
value;
Expand Down
4 changes: 4 additions & 0 deletions test/optimizer/level-1/optimize-test.js
Expand Up @@ -540,6 +540,10 @@ vows.describe('level 1 optimizations')
'with mixed bold weight and variant #2': [
'a{font:bold normal 17px sans-serif}',
'a{font:bold normal 17px sans-serif}'
],
'with color in local font name': [
'@font-face{src:local("Sans Black Italic")}',
'@font-face{src:local("Sans Black Italic")}',
]
}, { level: 1 })
)
Expand Down

0 comments on commit 3b2d0d2

Please sign in to comment.