Fixes #470 - negative padding.
authorJakub Pawlowicz <contact@jakubpawlowicz.com>
Fri, 27 Feb 2015 09:43:39 +0000 (09:43 +0000)
committerJakub Pawlowicz <contact@jakubpawlowicz.com>
Fri, 27 Feb 2015 19:14:48 +0000 (19:14 +0000)
Basically negative paddings are not allowed by browsers so we should
not merge them into shorthands.

History.md
lib/selectors/optimizers/simple.js
test/integration-test.js

index 8451246..a93b46f 100644 (file)
@@ -1,3 +1,8 @@
+[3.1.1 / 2015-xx-xx](https://github.com/jakubpawlowicz/clean-css/compare/v3.1.0...HEAD)
+==================
+
+* Fixed issue [#470](https://github.com/jakubpawlowicz/clean-css/issues/470) - negative padding removal.
+
 [3.1.0 / 2015-02-26](https://github.com/jakubpawlowicz/clean-css/compare/v3.0.10...3.1.0)
 ==================
 
index 3153e5f..af3acb6 100644 (file)
@@ -75,6 +75,16 @@ var valueMinifiers = {
   }
 };
 
+function isNegative(value) {
+  var parts = new Splitter(',').split(value);
+  for (var i = 0, l = parts.length; i < l; i++) {
+    if (parts[i][0] == '-' && parseFloat(parts[i]) < 0)
+      return true;
+  }
+
+  return false;
+}
+
 function zeroMinifier(_, value) {
   if (value.indexOf('0') == -1)
     return value;
@@ -200,6 +210,9 @@ function reduce(body, options) {
       important = true;
     }
 
+    if (property.indexOf('padding') === 0 && isNegative(value))
+      continue;
+
     if (property.indexOf('border') === 0 && property.indexOf('radius') > 0)
       value = valueMinifiers['border-*-radius'](value);
 
index ed0f2be..08607d4 100644 (file)
@@ -613,6 +613,20 @@ vows.describe('integration tests').addBatch({
       'div{padding:10em .05rem}'
     ]
   }),
+  'units': cssContext({
+    'negative padding': [
+      'div{padding-left:2px;padding-top:-2px;padding-right:5px;padding-bottom:0}',
+      'div{padding-left:2px;padding-right:5px;padding-bottom:0}'
+    ],
+    'negative padding after negative shorthand': [
+      'div{padding:-5px 0 0 0;padding-left:2px;padding-top:-2px;padding-right:5px;padding-bottom:0}',
+      'div{padding-left:2px;padding-right:5px;padding-bottom:0}'
+    ],
+    'negative padding in calculations': [
+      'div{padding:calc(100% - 5px) 0 0 0}',
+      'div{padding:calc(100% - 5px)0 0}'
+    ]
+  }),
   'floats': cssContext({
     'strips zero in fractions': [
       'a{ margin-bottom: 0.5em}',