Skip to content

Commit 233b7c9

Browse files
committed
Merge pull request #4 from vlad003/master
Leave units on 0 time values.
2 parents 3a2a788 + 1832b3b commit 233b7c9

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

csscompressor/__init__.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,12 @@
5757
_semi_re = re.compile(r';+}')
5858

5959
_zero_fmt_spec_re = re.compile(r'''(\s|:|\(|,)(?:0?\.)?0
60-
(?:px|em|%|in|cm|mm|pc|pt|ex|deg|g?rad|m?s|k?hz)''',
60+
(?:px|em|%|in|cm|mm|pc|pt|ex|deg|g?rad|k?hz)''',
6161
re.I | re.X)
6262

63+
_zero_req_unit_re = re.compile(r'''(\s|:|\(|,)(?:0?\.)?0
64+
(m?s)''', re.I | re.X)
65+
6366
_bg_pos_re = re.compile(r'''(background-position|webkit-mask-position|transform-origin|
6467
webkit-transform-origin|moz-transform-origin|o-transform-origin|
6568
ms-transform-origin):0(;|})''', re.I | re.X)
@@ -383,6 +386,9 @@ def _replace(match):
383386
# Replace 0(px,em,%) with 0.
384387
css = _zero_fmt_spec_re.sub(lambda match: match.group(1) + '0', css)
385388

389+
# Replace 0.0(m,ms) or .0(m,ms) with 0(m,ms)
390+
css = _zero_req_unit_re.sub(lambda match: match.group(1) + '0' + match.group(2), css)
391+
386392
# Replace 0 0 0 0; with 0.
387393
css = _quad_0_re.sub(r':0\1', css)
388394
css = _trip_0_re.sub(r':0\1', css)

csscompressor/tests/test_yui.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1505,7 +1505,7 @@ def test_yui_zeros(self):
15051505

15061506
"""
15071507

1508-
output = """a{margin:0;_padding-top:0;background-position:0 0;padding:0;transition:opacity 0;transition-delay:0;transform:rotate3d(0,0,0);pitch:0;pitch:0}"""
1508+
output = """a{margin:0;_padding-top:0;background-position:0 0;padding:0;transition:opacity 0s;transition-delay:0ms;transform:rotate3d(0,0,0);pitch:0;pitch:0}"""
15091509

15101510
self._test(input, output)
15111511

0 commit comments

Comments
 (0)