From: GoalSmashers Date: Sat, 30 Mar 2013 11:09:24 +0000 (+0100) Subject: Follow up to #86 removing line breaks and extra spaces on Windows. X-Git-Url: https://git.ndcode.org/public/gitweb.cgi?a=commitdiff_plain;h=70fca7f05f0aa343593cf47540820b61708ebf57;p=clean-css.git Follow up to #86 removing line breaks and extra spaces on Windows. --- diff --git a/lib/clean.js b/lib/clean.js index 05b488d5..3779351c 100644 --- a/lib/clean.js +++ b/lib/clean.js @@ -338,14 +338,14 @@ var CleanCSS = { replace(function moveCharset() { // get first charset in stylesheet var match = data.match(/@charset [^;]+;/); - var firstCharset = match ? match[0] : ''; - - // remove all charsets - data = data.replace(/@charset [^;]+;\n?/g, ''); - - // reattach first charset - if (firstCharset !== '') - data = firstCharset + (options.keepBreaks ? lineBreak : '') + data; + var firstCharset = match ? match[0] : null; + if (!firstCharset) + return; + + // reattach first charset and remove all subsequent + data = firstCharset + + (options.keepBreaks ? lineBreak : '') + + data.replace(new RegExp('@charset [^;]+;(' + lineBreak + ')?', 'g'), ''); }); // trim spaces at beginning and end diff --git a/test/unit-test.js b/test/unit-test.js index 13349b88..1b2d7f6e 100644 --- a/test/unit-test.js +++ b/test/unit-test.js @@ -159,6 +159,10 @@ vows.describe('clean-units').addBatch({ 'charset multiple charsets': [ "@charset 'utf-8';\ndiv :before { display: block }\n@charset 'utf-8';\na { color: #f10 }", "@charset 'utf-8';" + lineBreak + "div :before{display:block}" + lineBreak + "a{color:#f10}" + ], + 'charset with double line break': [ + "@charset 'utf-8';" + lineBreak + lineBreak + "a{}", + "@charset 'utf-8';" + lineBreak + "a{}" ] }, { keepBreaks: true }), 'selectors': cssContext({ @@ -693,6 +697,10 @@ title']", 'multiple charsets': [ "@charset 'utf-8';div :before { display: block }@charset 'utf-8';a { color: #f10 }", "@charset 'utf-8';div :before{display:block}a{color:#f10}" + ], + 'charset and space after': [ + "@charset 'utf-8';" + lineBreak + lineBreak + "a{}", + "@charset 'utf-8';a{}" ] }), 'important': cssContext({