Skip to content

Commit

Permalink
Fixes #80 - quotation in multi line strings.
Browse files Browse the repository at this point in the history
  • Loading branch information
GoalSmashers committed Mar 22, 2013
1 parent 4309611 commit 8acc7a0
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 10 deletions.
1 change: 1 addition & 0 deletions History.md
Expand Up @@ -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
==================
Expand Down
15 changes: 9 additions & 6 deletions lib/clean.js
Expand Up @@ -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, {
Expand All @@ -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
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion test/data/big-min.css
Expand Up @@ -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}
Expand Down
3 changes: 2 additions & 1 deletion test/data/line-breaks-in-attributes-min.css
@@ -1 +1,2 @@
.test[title="my very long title"]{background-image:url("very/long/path")}
.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)}
7 changes: 6 additions & 1 deletion test/data/line-breaks-in-attributes.css
@@ -1,3 +1,8 @@
.test[title="my very long \
title"]{background-image:url("very/long/\
path")}
path")}
.test[title="my_very_long_\
title"] {
background-image: url("my/very/long/\
path")
}
12 changes: 11 additions & 1 deletion test/unit-test.js
Expand Up @@ -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({
Expand Down Expand Up @@ -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}',
Expand All @@ -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({
Expand Down

0 comments on commit 8acc7a0

Please sign in to comment.