From 30ed70f1ddb91eec5e357a7f3815cf3802039648 Mon Sep 17 00:00:00 2001 From: GoalSmashers Date: Sat, 16 Mar 2013 21:15:47 +0100 Subject: [PATCH] Stripping line breaks in attributes & urls. Follow up to #46. --- .jshintrc | 1 + lib/clean.js | 2 +- test/data/line-breaks-in-attributes-min.css | 1 + test/data/line-breaks-in-attributes.css | 3 +++ test/unit-test.js | 15 ++++++++++++--- 5 files changed, 18 insertions(+), 4 deletions(-) create mode 100644 test/data/line-breaks-in-attributes-min.css create mode 100644 test/data/line-breaks-in-attributes.css diff --git a/.jshintrc b/.jshintrc index 37b4fe3a..6a65f5e0 100644 --- a/.jshintrc +++ b/.jshintrc @@ -7,6 +7,7 @@ "curly": false, "eqeqeq": false, "latedef": true, + "multistr": true, "noarg": true, "plusplus": false, "regexp": false, diff --git a/lib/clean.js b/lib/clean.js index 51215fe4..5b5fdf4e 100644 --- a/lib/clean.js +++ b/lib/clean.js @@ -301,7 +301,7 @@ var CleanCSS = { }); replace(/__CSSFREETEXT__/g, function() { - return context.freeTextBlocks.shift(); + return context.freeTextBlocks.shift().replace(/\\(\r\n|\n)/mg, ''); }); var specialCommentsCount = context.specialComments.length; diff --git a/test/data/line-breaks-in-attributes-min.css b/test/data/line-breaks-in-attributes-min.css new file mode 100644 index 00000000..5cb9866c --- /dev/null +++ b/test/data/line-breaks-in-attributes-min.css @@ -0,0 +1 @@ +.test[title="my very longtitle"]{background-image:url("very/long/path")} \ No newline at end of file diff --git a/test/data/line-breaks-in-attributes.css b/test/data/line-breaks-in-attributes.css new file mode 100644 index 00000000..5929e55d --- /dev/null +++ b/test/data/line-breaks-in-attributes.css @@ -0,0 +1,3 @@ +.test[title="my very long\ +title"]{background-image:url("very/long/\ +path")} \ No newline at end of file diff --git a/test/unit-test.js b/test/unit-test.js index e7fac14f..b96808da 100644 --- a/test/unit-test.js +++ b/test/unit-test.js @@ -532,7 +532,12 @@ vows.describe('clean-units').addBatch({ 'keep urls from being stripped down #1': 'a{background:url(/image-1.0.png)}', 'keep urls from being stripped down #2': "a{background:url(/image-white.png)}", 'keep urls from being stripped down #3': "a{background:#eee url(libraries/jquery-ui-1.10.1.custom/images/ui-bg_highlight-soft_100_eeeeee_1x100.png) 50% top repeat-x}", - 'keep __URL__ in comments (so order is important)': '/*! __URL__ */a{}' + 'keep __URL__ in comments (so order is important)': '/*! __URL__ */a{}', + 'strip new line in urls': [ + 'a{background:url(/very/long/\ +path)}', + 'a{background:url(/very/long/path)}' + ] }), 'fonts': cssContext({ 'keep format quotation': "@font-face{font-family:PublicVintage;src:url(./PublicVintage.otf) format('opentype')}", @@ -609,8 +614,12 @@ vows.describe('clean-units').addBatch({ 'a[data-href*=object1]{border-color:red}a[data-href|=object2]{border-color:#0f0}' ], 'should keep special characters inside attributes #1': "a[data-css='color:white']", - 'should keep special characters inside attributes #2': "a[data-text='a\nb\nc']", - 'should keep special characters inside attributes #3': 'a[href="/version-0.01.html"]' + 'should keep special characters inside attributes #2': 'a[href="/version-0.01.html"]', + 'should strip new lines inside attributes': [ + ".test[title='my very long\ +title']", + ".test[title='my very longtitle']" + ] }), 'ie filters': cssContext({ 'short alpha': [ -- 2.34.1