From 5d6717b0f485466c1122b6baee36e8156aa421f2 Mon Sep 17 00:00:00 2001 From: GoalSmashers Date: Mon, 8 Jul 2013 16:22:22 +0200 Subject: [PATCH] Fixes issue #117 - handling line break escaping in comments. --- lib/clean.js | 4 ++-- test/data/issue-117-snippet-min.css | 3 +++ test/data/issue-117-snippet.css | 19 +++++++++++++++++++ test/unit-test.js | 4 ++++ 4 files changed, 28 insertions(+), 2 deletions(-) create mode 100644 test/data/issue-117-snippet-min.css create mode 100644 test/data/issue-117-snippet.css diff --git a/lib/clean.js b/lib/clean.js index de6f9898..11be0df7 100644 --- a/lib/clean.js +++ b/lib/clean.js @@ -80,11 +80,11 @@ var CleanCSS = { }); }; + removeComments(); + // replace all escaped line breaks replace(/\\(\r\n|\n)/mg, ''); - removeComments(); - // inline all imports replace(function inlineImports() { data = CleanCSS._inlineImports(data, { diff --git a/test/data/issue-117-snippet-min.css b/test/data/issue-117-snippet-min.css new file mode 100644 index 00000000..66c06784 --- /dev/null +++ b/test/data/issue-117-snippet-min.css @@ -0,0 +1,3 @@ +@media only print{a,a:visited{text-decoration:underline} +a[href]:after{content:" (" attr(href) ")"} +abbr[title]:after{content:" (" attr(title) ")"}} diff --git a/test/data/issue-117-snippet.css b/test/data/issue-117-snippet.css new file mode 100644 index 00000000..39a47f43 --- /dev/null +++ b/test/data/issue-117-snippet.css @@ -0,0 +1,19 @@ +@media print, (-o-min-device-pixel-ratio: 5/4), (-webkit-min-device-pixel-ratio: 1.25), (min-resolution: 120dpi) { + /* Style adjustments for high resolution devices */ +} +/**===================================================**\ +/** PRINT STYLES +/**===================================================**/ +@media only print { + a, + a:visited { + text-decoration: underline; + } + a[href]:after { + content: " (" attr(href) ")"; + } + abbr[title]:after { + content: " (" attr(title) ")"; + } + /** MANUALLY TRUNCATED FOR BREVITY **/ +} diff --git a/test/unit-test.js b/test/unit-test.js index a965694b..e2c7d8b7 100644 --- a/test/unit-test.js +++ b/test/unit-test.js @@ -226,6 +226,10 @@ vows.describe('clean-units').addBatch({ 'should remove comments with forward slashes inside': [ '/*////*/a{color:red}', 'a{color:red}' + ], + 'should properly handle line breaks and ** characters inside comments': [ + '/**====**\\\n/**2nd comment line/**===**/a{color:red}', + 'a{color:red}' ] }), 'important comments - one': cssContext({ -- 2.34.1