diff --git a/src/index.js b/src/index.js index 33c80a9..d0cf89c 100755 --- a/src/index.js +++ b/src/index.js @@ -49,7 +49,9 @@ function sqwish(css, strict) { // convert longhand hex to shorthand hex .replace(/#([a-fA-F0-9])\1([a-fA-F0-9])\2([a-fA-F0-9])\3(?![a-fA-F0-9])/g, '#$1$2$3') // Restore Microsoft longhand hex - .replace(/(Microsoft[^;}]*)#([a-fA-F0-9])([a-fA-F0-9])([a-fA-F0-9])(?![a-fA-F0-9])/g, '$1#$2$2$3$3$4$4') + .replace(/(Microsoft[^;}]*)/g, function(match) { + return match.replace(/#([a-fA-F0-9])([a-fA-F0-9])([a-fA-F0-9])(?![a-fA-F0-9])/g, '#$1$1$2$2$3$3') + }) // replace longhand values with shorthand '5px 5px 5px 5px' => '5px' .replace(/\b(\d+[a-z]{2}) \1 \1 \1/gi, '$1') diff --git a/tests/tests.js b/tests/tests.js index 1c1e6cb..3a0e25e 100644 --- a/tests/tests.js +++ b/tests/tests.js @@ -20,15 +20,15 @@ sink('basic mode', function (test, ok) { }) test('IE long hex is kept as long hex', 1, function () { - var input = "body { filter: progid:DXImageTransform.Microsoft.gradient(gradientType=0, startColorstr='#FFF2F2F2', endColorstr='#FFFFFFFF'); }" - , expected = "body{filter:progid:DXImageTransform.Microsoft.gradient(gradientType=0,startColorstr='#FFF2F2F2',endColorstr='#FFFFFFFF')}" + var input = "body { filter: progid:DXImageTransform.Microsoft.gradient(gradientType=0, startColorstr='#FFEEEEEE', endColorstr='#FFFFFFFF'); }" + , expected = "body{filter:progid:DXImageTransform.Microsoft.gradient(gradientType=0,startColorstr='#FFEEEEEE',endColorstr='#FFFFFFFF')}" , actual = sqwish.minify(input) ok(actual == expected, 'IE long hexes are kept that way') }) test('IE 6-digit hex is kept as 6-digit hex', 1, function () { - var input = "body { filter: progid:DXImageTransform.Microsoft.gradient(gradientType=0, startColorstr='#F2F2F2', endColorstr='#FFFFFF'); }" - , expected = "body{filter:progid:DXImageTransform.Microsoft.gradient(gradientType=0,startColorstr='#F2F2F2',endColorstr='#FFFFFF')}" + var input = "body { filter: progid:DXImageTransform.Microsoft.gradient(gradientType=0, startColorstr='#EEEEEE', endColorstr='#FFFFFF'); }" + , expected = "body{filter:progid:DXImageTransform.Microsoft.gradient(gradientType=0,startColorstr='#EEEEEE',endColorstr='#FFFFFF')}" , actual = sqwish.minify(input) ok(actual == expected, 'IE 6-digit hexes are kept that way') })