preserve '0%' in 'hsl()' and 'hsla()' calls

This commit is contained in:
Yury Selivanov 2013-10-08 15:53:07 -04:00
parent 56008d1204
commit 3f5bf4c7c7
2 changed files with 24 additions and 6 deletions

View File

@ -17,8 +17,9 @@ __all__ = ('compress',)
import re
_url_re = re.compile(r'''url\s*\(\s*(['"]?)data\:''', re.I)
_calc_re = re.compile(r'calc\s*\(', re.I)
_url_re = re.compile(r'''(url)\s*\(\s*(['"]?)data\:''', re.I)
_calc_re = re.compile(r'(calc)\s*\(', re.I)
_hsl_re = re.compile(r'(hsl|hsla)\s*\(', re.I)
_ws_re = re.compile(r'\s+')
_str_re = re.compile(r'''("([^\\"]|\\.|\\)*")|('([^\\']|\\.|\\)*')''')
_yui_comment_re = re.compile(r'___YUICSSMIN_PRESERVE_CANDIDATE_COMMENT_(?P<num>\d+)___')
@ -101,15 +102,16 @@ _colors_map = {
_colors_re = re.compile(r'(:|\s)' + '(\\#(' + '|'.join(_colors_map.keys()) + '))' + r'(;|})', re.I)
def _preserve_call_tokens(css, name, regexp, preserved_tokens, *, remove_ws=False):
def _preserve_call_tokens(css, regexp, preserved_tokens, *, remove_ws=False):
max_idx = len(css) - 1
append_idx = 0
sb = []
for match in regexp.finditer(css):
name = match.group(1)
start_idx = match.start(0) + len(name) + 1 # "len" of "url("
term = match.group(1) if match.lastindex else None
term = match.group(2) if match.lastindex > 1 else None
if not term:
term = ')'
@ -215,8 +217,9 @@ def compress(css, *, max_linelen=0):
total_len = len(css)
preserved_tokens = []
css = _preserve_call_tokens(css, 'url', _url_re, preserved_tokens, remove_ws=True)
css = _preserve_call_tokens(css, 'calc', _calc_re, preserved_tokens, remove_ws=False)
css = _preserve_call_tokens(css, _url_re, preserved_tokens, remove_ws=True)
css = _preserve_call_tokens(css, _calc_re, preserved_tokens, remove_ws=False)
css = _preserve_call_tokens(css, _hsl_re, preserved_tokens, remove_ws=True)
# Collect all comments blocks...
comments = []

View File

@ -41,3 +41,18 @@ class Tests(BaseTest):
output = '''.issue-59{width:100%;width:-webkit-calc(100% + 30px);width:-moz-calc(100% + 30px);width:calc(100% + 30px)}'''
self._test(input, output)
def test_issue_81(self):
# https://github.com/yui/yuicompressor/issues/81
input = '''
.SB-messages .SB-message a {
color: rgb(185, 99, 117);
border-bottom: 1px dotted text-shadow: 0 1px 0 hsl(0, 0%, 0%);
text-shadow: 0 1px 0 hsla(0, 0%, 0%, 1);
}
'''
output = '.SB-messages .SB-message a{color:#b96375;border-bottom:1px dotted text-shadow:0 1px 0 hsl(0,0%,0%);text-shadow:0 1px 0 hsla(0,0%,0%,1)}'
self._test(input, output)