From: GoalSmashers Date: Fri, 22 Mar 2013 06:30:31 +0000 (+0100) Subject: Fixes #80 - quotation in multi line strings. X-Git-Url: https://git.ndcode.org/public/gitweb.cgi?a=commitdiff_plain;h=8acc7a0be91ee0374c3fd8ddf23e4625fcf0f0cf;p=clean-css.git Fixes #80 - quotation in multi line strings. --- diff --git a/History.md b/History.md index a468e274..7fe1fc18 100644 --- a/History.md +++ b/History.md @@ -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 ================== diff --git a/lib/clean.js b/lib/clean.js index dbfec82b..97d53adb 100644 --- a/lib/clean.js +++ b/lib/clean.js @@ -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; diff --git a/test/data/big-min.css b/test/data/big-min.css index 55876d0c..4b5e08a5 100644 --- a/test/data/big-min.css +++ b/test/data/big-min.css @@ -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} diff --git a/test/data/line-breaks-in-attributes-min.css b/test/data/line-breaks-in-attributes-min.css index 0d893019..d0ac4c0f 100644 --- a/test/data/line-breaks-in-attributes-min.css +++ b/test/data/line-breaks-in-attributes-min.css @@ -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 diff --git a/test/data/line-breaks-in-attributes.css b/test/data/line-breaks-in-attributes.css index b657b328..5492aa69 100644 --- a/test/data/line-breaks-in-attributes.css +++ b/test/data/line-breaks-in-attributes.css @@ -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 diff --git a/test/unit-test.js b/test/unit-test.js index 7044bad8..2baee8c7 100644 --- a/test/unit-test.js +++ b/test/unit-test.js @@ -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({