From cfb385507f63d019fd85ec3ddc1182f724ee0530 Mon Sep 17 00:00:00 2001 From: Jonathan-L Date: Thu, 3 Jul 2014 12:52:45 +0100 Subject: [PATCH] Fixes #311 - exception with leading/trailing decimal point. --- History.md | 5 +++++ lib/clean.js | 7 +++++-- test/unit-test.js | 12 ++++++++++++ 3 files changed, 22 insertions(+), 2 deletions(-) diff --git a/History.md b/History.md index fca2ce86..bfebc2c6 100644 --- a/History.md +++ b/History.md @@ -1,3 +1,8 @@ +[2.2.6 / 2014-xx-xx](https://github.com/GoalSmashers/clean-css/compare/v2.2.5...v2.2.6) +================== + +* Fixed issue [#311](https://github.com/GoalSmashers/clean-css/issues/311) - leading/trailing decimal points. + [2.2.5 / 2014-06-29](https://github.com/GoalSmashers/clean-css/compare/v2.2.4...v2.2.5) ================== diff --git a/lib/clean.js b/lib/clean.js index d5d41685..f5c1128e 100644 --- a/lib/clean.js +++ b/lib/clean.js @@ -272,7 +272,10 @@ var minify = function(data, callback) { }); // .0 to 0 - replace(/(\D)\.0+(,|\}|\))/g, '$10$2'); + // repeated twice on purpose as if not it doesn't process {padding: .0 .0 .0 .0} correctly + var leadingDecimalRegexp = /(\D)\.0+(\D)/g; + replace(leadingDecimalRegexp, '$10$2'); + replace(leadingDecimalRegexp, '$10$2'); // fraction zeros removal replace(/\.([1-9]*)0+(\D)/g, function(match, nonZeroPart, suffix) { @@ -285,7 +288,7 @@ var minify = function(data, callback) { units.push('rem'); replace(new RegExp('(\\s|:|,)\\-?0(?:' + units.join('|') + ')', 'g'), '$1' + '0'); - replace(new RegExp('(\\s|:|,)\\-?(\\d)\\.(\\D)', 'g'), '$1$2$3'); + replace(new RegExp('(\\s|:|,)\\-?(\\d+)\\.(\\D)', 'g'), '$1$2$3'); replace(new RegExp('rect\\(0(?:' + units.join('|') + ')', 'g'), 'rect(0'); // restore % in rgb/rgba and hsl/hsla diff --git a/test/unit-test.js b/test/unit-test.js index 84fd2a1a..2dd4a23a 100644 --- a/test/unit-test.js +++ b/test/unit-test.js @@ -434,6 +434,14 @@ vows.describe('clean-units').addBatch({ 'body{margin:.0}', 'body{margin:0}' ], + 'zero as .0 #3': [ + 'body{margin:.0em}', + 'body{margin:0}' + ], + 'zero as .0 #4': [ + 'body{margin:.0 1em .0 .0}', + 'body{margin:0 1em 0 0}' + ], 'missing #1': [ 'body{margin:2.em}', 'body{margin:2em}' @@ -442,6 +450,10 @@ vows.describe('clean-units').addBatch({ 'p{opacity:1.}', 'p{opacity:1}' ], + 'missing #3': [ + 'p{opacity:11.px}', + 'p{opacity:11px}' + ], 'minus zero as value to zero': [ 'body{margin:-0}', 'body{margin:0}' -- 2.34.1