Fixes #80 - quotation in multi line strings.
authorGoalSmashers <jakub@goalsmashers.com>
Fri, 22 Mar 2013 06:30:31 +0000 (07:30 +0100)
committerGoalSmashers <jakub@goalsmashers.com>
Fri, 22 Mar 2013 06:30:31 +0000 (07:30 +0100)
History.md
lib/clean.js
test/data/big-min.css
test/data/line-breaks-in-attributes-min.css
test/data/line-breaks-in-attributes.css
test/unit-test.js

index a468e27..7fe1fc1 100644 (file)
@@ -6,6 +6,7 @@
 * Fixed issue [#44](https://github.com/GoalSmashers/clean-css/issues/44) - examples in --help.
 * Fixed issue [#83](https://github.com/GoalSmashers/clean-css/issues/83) - HSL to hex color conversions.
 * Fixed issue [#2](https://github.com/GoalSmashers/clean-css/issues/2) - resolving @import rules.
+* Fixed issue [#80](https://github.com/GoalSmashers/clean-css/issues/80) - quotation in multi line strings.
 
 0.10.2 / 2013-03-19
 ==================
index dbfec82..97d53ad 100644 (file)
@@ -74,6 +74,9 @@ var CleanCSS = {
       };
     }
 
+    // replace all escaped line breaks
+    replace(/\\(\r\n|\n)/mg, '');
+
     // inline all imports
     replace(function inlineImports() {
       data = CleanCSS._inlineImports(data, {
@@ -88,11 +91,11 @@ var CleanCSS = {
     });
 
     // strip parentheses in urls if possible (no spaces inside)
-    replace(/url\(['"]([^\)]+)['"]\)/g, function(urlMatch) {
-      if (urlMatch.match(/\s/g) !== null)
-        return urlMatch;
+    replace(/url\((['"])([^\)]+)['"]\)/g, function(match, quote, url) {
+      if (url.match(/[ \t]/g) !== null)
+        return 'url(' + quote + url + quote + ')';
       else
-        return urlMatch.replace(/\(['"]/, '(').replace(/['"]\)$/, ')');
+        return 'url(' + url + ')';
     });
 
     // strip parentheses in animation & font names
@@ -120,7 +123,7 @@ var CleanCSS = {
       var key = content.substring(0, eqIndex);
       var value = content.substring(eqIndex + 1, content.length);
 
-      if (/^['"](?:[a-zA-Z][a-zA-Z\d\-]+)['"]$/.test(value))
+      if (/^['"](?:[a-zA-Z][a-zA-Z\d\-_]+)['"]$/.test(value))
         return '[' + key + '=' + value.substring(1, value.length - 1) + ']';
       else
         return match;
@@ -327,7 +330,7 @@ var CleanCSS = {
     });
 
     replace(/__CSSFREETEXT__/g, function() {
-      return context.freeTextBlocks.shift().replace(/\\(\r\n|\n)/mg, '');
+      return context.freeTextBlocks.shift();
     });
 
     var specialCommentsCount = context.specialComments.length;
index 55876d0..4b5e08a 100644 (file)
@@ -1002,7 +1002,7 @@ label i{display:none;font-style:normal;display:none}
 .liste_reactions .bulle span{display:block;-webkit-box-shadow:0 3px 2px 1px rgba(0,11,21,.2);-moz-box-shadow:0 3px 2px 1px rgba(0,11,21,.2);box-shadow:0 3px 2px 1px rgba(0,11,21,.2);border-radius:4px;padding:10px;background:#fff}
 .liste_reactions .references{font-weight:700}
 .liste_reactions .references .date{color:#8b9299}
-.liste_reactions input[class=btn],.liste_reactions input[class="btn_abo"]{margin:5px 0 10px}
+.liste_reactions input[class=btn],.liste_reactions input[class=btn_abo]{margin:5px 0 10px}
 .reaction_identifier,.reaction_redaction{margin:20px 0;background:#f5f8f9;border-top:3px solid #e9ecf0}
 .reaction_redaction{padding:0 0 10px}
 .reaction_identifier .deja_abo{float:left;width:275px;border-left:1px solid #ebeff0}
index 0d89301..d0ac4c0 100644 (file)
@@ -1 +1,2 @@
-.test[title="my very long title"]{background-image:url("very/long/path")}
\ No newline at end of file
+.test[title="my very long title"]{background-image:url(very/long/path)}
+.test[title=my_very_long_title]{background-image:url(my/very/long/path)}
\ No newline at end of file
index b657b32..5492aa6 100644 (file)
@@ -1,3 +1,8 @@
 .test[title="my very long \
 title"]{background-image:url("very/long/\
-path")}
\ No newline at end of file
+path")}
+.test[title="my_very_long_\
+title"] {
+    background-image: url("my/very/long/\
+path")
+}
\ No newline at end of file
index 7044bad..2baee8c 100644 (file)
@@ -565,6 +565,11 @@ vows.describe('clean-units').addBatch({
       'a{background:url(/very/long/\
 path)}',
       'a{background:url(/very/long/path)}'
+    ],
+    'strip new line in urls which could be unquoted': [
+      'a{background:url("/very/long/\
+path")}',
+      'a{background:url(/very/long/path)}'
     ]
   }),
   'fonts': cssContext({
@@ -625,7 +630,7 @@ path)}',
     'should keep selector if no quotation': 'div[data-type=something]{border-color:red}',
     'should keep selector if equals in value': 'div[data-type="stupid=value"]{border-color:red}',
     'should keep quotation if whitespace inside': 'div[data-type^=\'object 1\']{border-color:red}',
-    'should keep quotations if special characters inside': 'a[data-type="object_1"]{color:red}a[data-target="#some-place"]{color:red}',
+    'should keep quotations if special characters inside': 'a[data-type="object+1"]{color:red}a[data-target="#some-place"]{color:red}',
     'should keep quotation if is a number': 'div[data-number=\'1\']{border-color:red}',
     'should keep quotation if starts with a number': 'div[data-type^=\'1something\']{border-color:red}',
     'should keep quotation if starts with a hyphen': 'div[data-type$=\'-something\']{border-color:red}',
@@ -647,6 +652,11 @@ path)}',
       ".test[title='my very long \
 title']",
       ".test[title='my very long title']"
+    ],
+    'should strip new lines inside attributes which can be unquoted': [
+      ".test[title='my_very_long_\
+title']",
+      ".test[title=my_very_long_title]"
     ]
   }),
   'ie filters': cssContext({