Repository: sprymix/csscompressor

Issue:
Omitting the unit on a time value is invalid
Input: `csscompressor.compress("transition: background-color 1s linear 0ms;")`
Expected output: `'transition:background-color 1s linear 0ms;'`
Actual output: `'transition:background-color 1s linear 0;'`

According to the [MDN page on \<time>](https://developer.mozilla.org/en-US/docs/Web/CSS/time), omitting the unit is only valid for \<length>, so when I use csscompressor, the declaration containing the 0ms or 0s is ignored by both Firefox and Chrome.

The same case is for `<frequency>`, and probably a few of the other ones, I think. Omitting the unit used to be valid in CSS2, but breaks in CSS3 unfortunately.

This is a fairly simple fix (removing the `m?s` from `_zero_fmt_spec_re`), and I'll create a PR and some tests.

Discussion:

Patch:
diff --git a/csscompressor/__init__.py b/csscompressor/__init__.py
index 1b41119..1233cd3 100644
--- a/csscompressor/__init__.py
+++ b/csscompressor/__init__.py
@@ -56,9 +56,12 @@ _space_after_re = re.compile(r'([!{}:;>+\(\[,])\s+')
 _semi_re = re.compile(r';+}')
 
 _zero_fmt_spec_re = re.compile(r'''(\s|:|\(|,)(?:0?\.)?0
-                                    (?:px|em|%|in|cm|mm|pc|pt|ex|deg|g?rad|m?s|k?hz)''',
+                                    (?:px|em|%|in|cm|mm|pc|pt|ex|deg|g?rad|k?hz)''',
                                re.I | re.X)
 
+_zero_req_unit_re = re.compile(r'''(\s|:|\(|,)(?:0?\.)?0
+                                    (m?s)''', re.I | re.X)
+
 _bg_pos_re = re.compile(r'''(background-position|webkit-mask-position|transform-origin|
                                 webkit-transform-origin|moz-transform-origin|o-transform-origin|
                                 ms-transform-origin):0(;|})''', re.I | re.X)
@@ -377,6 +380,9 @@ def _compress(css, max_linelen=0):
     # Replace 0(px,em,%) with 0.
     css = _zero_fmt_spec_re.sub(lambda match: match.group(1) + '0', css)
 
+    # Replace 0.0(m,ms) or .0(m,ms) with 0(m,ms)
+    css = _zero_req_unit_re.sub(lambda match: match.group(1) + '0' + match.group(2), css)
+
     # Replace 0 0 0 0; with 0.
     css = _quad_0_re.sub(r':0\1', css)
     css = _trip_0_re.sub(r':0\1', css)


Test patch:
diff --git a/csscompressor/tests/test_yui.py b/csscompressor/tests/test_yui.py
index a0d6715..5d56d24 100644
--- a/csscompressor/tests/test_yui.py
+++ b/csscompressor/tests/test_yui.py
@@ -1458,7 +1458,7 @@ serve! */"""
 
         """
 
-        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}"""
+        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}"""
 
         self._test(input, output)