From: GoalSmashers Date: Wed, 11 Dec 2013 18:24:08 +0000 (+0100) Subject: Fixes #186 - strips unit from `0rem` unless in ie8 compatibility mode. X-Git-Url: https://git.ndcode.org/public/gitweb.cgi?a=commitdiff_plain;h=b4ce938330a899a609f7e0cf55c92309287ff716;p=clean-css.git Fixes #186 - strips unit from `0rem` unless in ie8 compatibility mode. --- diff --git a/History.md b/History.md index 2933e80a..bfd4060d 100644 --- a/History.md +++ b/History.md @@ -7,6 +7,7 @@ * Fixed issue [#161](https://github.com/GoalSmashers/clean-css/issues/161) - improves tokenizer performance. * Fixed issue [#163](https://github.com/GoalSmashers/clean-css/issues/163) - round pixels to 2nd decimal place. * Fixed issue [#165](https://github.com/GoalSmashers/clean-css/issues/165) - extra space after trailing parenthesis. +* Fixed issue [#186](https://github.com/GoalSmashers/clean-css/issues/186) - strip unit from 0rem. [2.0.2 / 2013-11-18](https://github.com/GoalSmashers/clean-css/compare/v2.0.1...v2.0.2) ================== diff --git a/lib/clean.js b/lib/clean.js index 6ea60f1f..87225447 100644 --- a/lib/clean.js +++ b/lib/clean.js @@ -230,8 +230,12 @@ CleanCSS.prototype.minify = function(data) { }); // zero + unit to zero - replace(/(\s|:|,)0(?:px|em|ex|cm|mm|in|pt|pc|%)/g, '$1' + '0'); - replace(/rect\(0(?:px|em|ex|cm|mm|in|pt|pc|%)/g, 'rect(0'); + var units = ['px', 'em', 'ex', 'cm', 'mm', 'in', 'pt', 'pc', '%']; + if ('ie8' != options.compatibility) + units.push('rem'); + + replace(new RegExp('(\\s|:|,)0(?:' + units.join('|') + ')', 'g'), '$1' + '0'); + replace(new RegExp('rect\\(0(?:' + units.join('|') + ')', 'g'), 'rect(0'); // round pixels to 2nd decimal place replace(/\.(\d{3,})px/g, function(match, decimalPlaces) { diff --git a/test/unit-test.js b/test/unit-test.js index 59f7e44c..d872288e 100644 --- a/test/unit-test.js +++ b/test/unit-test.js @@ -405,11 +405,24 @@ vows.describe('clean-units').addBatch({ 'a{box-shadow:0 0 0 0}', 'a{box-shadow:0 0}' ], + 'rems': [ + 'div{width:0rem;height:0rem}', + 'div{width:0;height:0}' + ], 'prefixed box shadow zeros': [ 'a{-webkit-box-shadow:0 0 0 0; -moz-box-shadow:0 0 0 0}', 'a{-webkit-box-shadow:0 0;-moz-box-shadow:0 0}' ] }), + 'zero values in ie8 compatibility mode': cssContext({ + 'rems': 'div{width:0rem;height:0rem}' + }, { compatibility: 'ie8' }), + 'zero values in any other compatibility mode': cssContext({ + 'rems': [ + 'div{width:0rem;height:0rem}', + 'div{width:0;height:0}' + ] + }, { compatibility: '*' }), 'shorthands': cssContext({ 'padding - same 4 values': [ 'div{padding:1px 1px 1px 1px}',