From acd5843e4e3363f91b40028ede83a831934860db Mon Sep 17 00:00:00 2001 From: Jakub Pawlowicz Date: Tue, 17 Mar 2015 20:13:36 +0000 Subject: [PATCH] Fixes #499 - too aggressive `-` removal. So far we don't check if a stripped value is a numerical one so we should be extra careful about removing such values. --- History.md | 1 + lib/selectors/optimizers/simple.js | 8 ++++++-- test/selectors/optimizers/simple-test.js | 16 ++++++++++++++++ 3 files changed, 23 insertions(+), 2 deletions(-) diff --git a/History.md b/History.md index 3b821201..88552e44 100644 --- a/History.md +++ b/History.md @@ -12,6 +12,7 @@ [3.1.8 / 2015-xx-xx](https://github.com/jakubpawlowicz/clean-css/compare/v3.1.7...3.1) ================== +* Fixes issue [#499](https://github.com/jakubpawlowicz/clean-css/issues/499) - too aggressive `-` removal. * Fixes issue [#498](https://github.com/jakubpawlowicz/clean-css/issues/498) - reordering and flexbox. [3.1.7 / 2015-03-16](https://github.com/jakubpawlowicz/clean-css/compare/v3.1.6...v3.1.7) diff --git a/lib/selectors/optimizers/simple.js b/lib/selectors/optimizers/simple.js index a9bd64d8..028dbc60 100644 --- a/lib/selectors/optimizers/simple.js +++ b/lib/selectors/optimizers/simple.js @@ -89,9 +89,13 @@ function zeroMinifier(_, value) { if (value.indexOf('0') == -1) return value; + if (value.indexOf('-') > -1) { + value = value + .replace(/([^\w\d\-]|^)\-0([^\.]|$)/g, '$10$2') + .replace(/([^\w\d\-]|^)\-0([^\.]|$)/g, '$10$2'); + } + return value - .replace(/\-0$/g, '0') - .replace(/\-0([^\.])/g, '0$1') .replace(/(^|\s)0+([1-9])/g, '$1$2') .replace(/(^|\D)\.0+(\D|$)/g, '$10$2') .replace(/(^|\D)\.0+(\D|$)/g, '$10$2') diff --git a/test/selectors/optimizers/simple-test.js b/test/selectors/optimizers/simple-test.js index 268d3782..b7f03b8a 100644 --- a/test/selectors/optimizers/simple-test.js +++ b/test/selectors/optimizers/simple-test.js @@ -441,6 +441,10 @@ vows.describe(SimpleOptimizer) 'a{margin:-0px}', ['margin:0'] ], + '-0% to 0': [ + 'a{width:-0%}', + ['width:0'] + ], 'missing': [ 'a{opacity:1.}', ['opacity:1'] @@ -453,6 +457,18 @@ vows.describe(SimpleOptimizer) 'a{margin:-0.5em}', ['margin:-.5em'] ], + 'inside names #1': [ + 'div{animation-name:test-0-bounce}', + ['animation-name:test-0-bounce'] + ], + 'inside names #2': [ + 'div{animation-name:test-0bounce}', + ['animation-name:test-0bounce'] + ], + 'inside names #3': [ + 'div{animation-name:test-0px}', + ['animation-name:test-0px'] + ], 'strips leading from value': [ 'a{padding:010px 0015px}', ['padding:10px 15px'] -- 2.34.1