Stripping line breaks in attributes & urls. Follow up to #46.
authorGoalSmashers <jakub@goalsmashers.com>
Sat, 16 Mar 2013 20:15:47 +0000 (21:15 +0100)
committerGoalSmashers <jakub@goalsmashers.com>
Sat, 16 Mar 2013 20:16:01 +0000 (21:16 +0100)
.jshintrc
lib/clean.js
test/data/line-breaks-in-attributes-min.css [new file with mode: 0644]
test/data/line-breaks-in-attributes.css [new file with mode: 0644]
test/unit-test.js

index 37b4fe3..6a65f5e 100644 (file)
--- a/.jshintrc
+++ b/.jshintrc
@@ -7,6 +7,7 @@
   "curly": false,
   "eqeqeq": false,
   "latedef": true,
+  "multistr": true,
   "noarg": true,
   "plusplus": false,
   "regexp": false,
index 51215fe..5b5fdf4 100644 (file)
@@ -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 (file)
index 0000000..5cb9866
--- /dev/null
@@ -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 (file)
index 0000000..5929e55
--- /dev/null
@@ -0,0 +1,3 @@
+.test[title="my very long\
+title"]{background-image:url("very/long/\
+path")}
\ No newline at end of file
index e7fac14..b96808d 100644 (file)
@@ -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': [