Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix local fonts with colors in name #1077

Merged
merged 2 commits into from Sep 17, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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