From 8ed81b8c16897d44c0f65d999085a302704b4ebf Mon Sep 17 00:00:00 2001 From: GoalSmashers Date: Sat, 30 Mar 2013 10:04:41 +0100 Subject: [PATCH] Fixes #86 - broken charset replacing when preceeded by text content. --- History.md | 1 + lib/clean.js | 28 +++++++++++----------- test/data/charset-mixed-with-fonts-min.css | 3 +++ test/data/charset-mixed-with-fonts.css | 14 +++++++++++ 4 files changed, 32 insertions(+), 14 deletions(-) create mode 100644 test/data/charset-mixed-with-fonts-min.css create mode 100644 test/data/charset-mixed-with-fonts.css diff --git a/History.md b/History.md index a2e187b5..d909401c 100644 --- a/History.md +++ b/History.md @@ -9,6 +9,7 @@ * 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. * Fixed issue [#88](https://github.com/GoalSmashers/clean-css/issues/88) - removes space in '! important'. +* Fixed issue [#86](https://github.com/GoalSmashers/clean-css/issues/86) - broken @charset replacing. 0.10.2 / 2013-03-19 ================== diff --git a/lib/clean.js b/lib/clean.js index 6e1561a2..60293b62 100644 --- a/lib/clean.js +++ b/lib/clean.js @@ -295,20 +295,6 @@ var CleanCSS = { // restore rect(...) zeros syntax for 4 zeros replace(/rect\(\s?0(\s|,)0[ ,]0[ ,]0\s?\)/g, 'rect(0$10$10$10)'); - // move first charset to the beginning - 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; - }); - if (options.removeEmpty) { // empty elements replace(/[^\{\}]+\{\}/g, ''); @@ -348,6 +334,20 @@ var CleanCSS = { } }); + // move first charset to the beginning + 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; + }); + // trim spaces at beginning and end return data.trim(); }, diff --git a/test/data/charset-mixed-with-fonts-min.css b/test/data/charset-mixed-with-fonts-min.css new file mode 100644 index 00000000..c410169b --- /dev/null +++ b/test/data/charset-mixed-with-fonts-min.css @@ -0,0 +1,3 @@ +@charset "UTF-8"; +@font-face{font-family:ProximaNova-Regular;src:url(/assets/thirdParty/css/1415F2_1.eot);src:url(/assets/thirdParty/css/1415F2_1IE.eot) format('embedded-opentype'),url(/assets/thirdParty/css/1415F2_1.woff) format('woff'),url(/assets/thirdParty/css/1415F2_1.ttf) format('truetype'),url(/assets/thirdParty/css/1415F2_1.svg) format('svg')} +blockquote small:before{content:'\2014 \00A0'} diff --git a/test/data/charset-mixed-with-fonts.css b/test/data/charset-mixed-with-fonts.css new file mode 100644 index 00000000..23789670 --- /dev/null +++ b/test/data/charset-mixed-with-fonts.css @@ -0,0 +1,14 @@ +@font-face { + font-family: 'ProximaNova-Regular'; + src: url('/assets/thirdParty/css/1415F2_1.eot'); + src: url('/assets/thirdParty/css/1415F2_1IE.eot') format('embedded-opentype'), + url('/assets/thirdParty/css/1415F2_1.woff') format('woff'), + url('/assets/thirdParty/css/1415F2_1.ttf') format('truetype'), + url('/assets/thirdParty/css/1415F2_1.svg') format('svg'); +} + +@charset "UTF-8"; +/* (c) 2012 Instagram, Inc, */ +blockquote small:before { + content: '\2014 \00A0'; +} -- 2.34.1