From 9a3566805653b4b6836950658397bb4529be1237 Mon Sep 17 00:00:00 2001 From: Jakub Pawlowicz Date: Fri, 27 Feb 2015 09:43:39 +0000 Subject: [PATCH] Fixes #470 - negative padding. Basically negative paddings are not allowed by browsers so we should not merge them into shorthands. --- History.md | 5 +++++ lib/selectors/optimizers/simple.js | 13 +++++++++++++ test/integration-test.js | 14 ++++++++++++++ 3 files changed, 32 insertions(+) diff --git a/History.md b/History.md index 8451246e..a93b46fa 100644 --- a/History.md +++ b/History.md @@ -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) ================== diff --git a/lib/selectors/optimizers/simple.js b/lib/selectors/optimizers/simple.js index 3153e5fe..af3acb62 100644 --- a/lib/selectors/optimizers/simple.js +++ b/lib/selectors/optimizers/simple.js @@ -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); diff --git a/test/integration-test.js b/test/integration-test.js index ed0f2be6..08607d4c 100644 --- a/test/integration-test.js +++ b/test/integration-test.js @@ -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}', -- 2.34.1