From 91a1edebc458028ffa6b7058f9de685105ba72cb Mon Sep 17 00:00:00 2001 From: GoalSmashers Date: Fri, 29 Mar 2013 23:55:14 +0100 Subject: [PATCH] Fixes #92 - uppercase colors to shortened version(s). --- History.md | 1 + lib/clean.js | 6 +++--- test/unit-test.js | 8 ++++++++ 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/History.md b/History.md index 175abe77..64c56898 100644 --- a/History.md +++ b/History.md @@ -7,6 +7,7 @@ * Fixed issue [#83](https://github.com/GoalSmashers/clean-css/issues/83) - HSL to hex color conversions. * Fixed issue [#2](https://github.com/GoalSmashers/clean-css/issues/2) - resolving `@import` rules. * Fixed issue [#80](https://github.com/GoalSmashers/clean-css/issues/80) - quotation in multi line strings. +* Fixed issue [#92](https://github.com/GoalSmashers/clean-css/issues/92) - uppercase hex to short versions. 0.10.2 / 2013-03-19 ================== diff --git a/lib/clean.js b/lib/clean.js index dc1aec2c..9ae2efa0 100644 --- a/lib/clean.js +++ b/lib/clean.js @@ -208,10 +208,10 @@ var CleanCSS = { ['toHex', 'toName'].forEach(function(type) { var pattern = "(" + Object.keys(CleanCSS.colors[type]).join('|') + ")"; var colorSwitcher = function(match, prefix, colorValue, suffix) { - return prefix + CleanCSS.colors[type][colorValue] + suffix; + return prefix + CleanCSS.colors[type][colorValue.toLowerCase()] + suffix; }; - replace(new RegExp("([ :,\\(])" + pattern + "([;\\}!\\) ])", 'g'), colorSwitcher); - replace(new RegExp("(,)" + pattern + "(,)", 'g'), colorSwitcher); + replace(new RegExp("([ :,\\(])" + pattern + "([;\\}!\\) ])", 'ig'), colorSwitcher); + replace(new RegExp("(,)" + pattern + "(,)", 'ig'), colorSwitcher); }); // replace font weight with numerical value diff --git a/test/unit-test.js b/test/unit-test.js index 06ae154c..bec7b7a3 100644 --- a/test/unit-test.js +++ b/test/unit-test.js @@ -455,6 +455,14 @@ vows.describe('clean-units').addBatch({ 'p{color:#f00}', 'p{color:red}' ], + 'upper case hex value to color name if shorter': [ + 'p{color:#F00}', + 'p{color:red}' + ], + 'upper case long hex value to color name if shorter': [ + 'p{color:#FF0000}', + 'p{color:red}' + ], 'hex value to color name in borders': [ 'p{border:1px solid #f00}', 'p{border:1px solid red}' -- 2.34.1