Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Moved strings preservation before comments stripping, tests uupdated

  • Loading branch information...
commit 8a6d59eefaf3f8dc40330b82fa65dc91ecbe8f60 1 parent 7bfc416
Stoyan Stefanov authored
View
14 ports/js/cssmin.js
@@ -27,6 +27,13 @@ YAHOO.compressor.cssmin = function (css, linebreakpos){
preservedTokens = [],
token = '';
+ // preserve strings so their content doesn't get accidentally minified
+ css = css.replace(/("([^\\"]|\\.|\\)*")|('([^\\']|\\.|\\)*')/g, function(match) {
+ var quote = match[0];
+ preservedTokens.push(match.slice(1, -1));
+ return quote + "___YUICSSMIN_PRESERVED_TOKEN_" + (preservedTokens.length - 1) + "___" + quote;
+ });
+
// Remove all comment blocks...
while ((startIndex = css.indexOf("/*", startIndex)) >= 0) {
preserve = css.length > startIndex + 2 && css[startIndex + 2] === '!';
@@ -59,13 +66,6 @@ YAHOO.compressor.cssmin = function (css, linebreakpos){
}
}
- // preserve strings so their content doesn't get accidentally minified
- css = css.replace(/("([^\\"]|\\.|\\)*")|('([^\\']|\\.|\\)*')/g, function(match) {
- var quote = match[0];
- preservedTokens.push(match.slice(1, -1));
- return quote + "___YUICSSMIN_PRESERVED_TOKEN_" + (preservedTokens.length - 1) + "___" + quote;
- });
-
// Normalize all whitespace strings to single spaces. Easier to work with that way.
css = css.replace(/\s+/g, " ");
View
34 src/com/yahoo/platform/yui/compressor/CssCompressor.java
@@ -38,14 +38,27 @@ public void compress(Writer out, int linebreakpos)
StringBuffer sb;
int startIndex, endIndex;
ArrayList preservedTokens;
-
+
+ // preserve strings so their content doesn't get accidentally minified
+ preservedTokens = new ArrayList(0);
+ css = srcsb.toString();
+ sb = new StringBuffer();
+ p = Pattern.compile("(\"([^\\\\\"]|\\\\.|\\\\)*\")|(\'([^\\\\\']|\\\\.|\\\\)*\')");
+ m = p.matcher(css);
+ while (m.find()) {
+ token = m.group();
+ char quote = token.charAt(0);
+ token = token.substring(1, token.length() - 1);
+ preservedTokens.add(token);
+ String preserver = quote + "___YUICSSMIN_PRESERVED_TOKEN_" + (preservedTokens.size() - 1) + "___" + quote;
+ m.appendReplacement(sb, preserver);
+ }
+ m.appendTail(sb);
// Remove all comment blocks...
startIndex = 0;
boolean iemac = false;
boolean preserve = false;
- preservedTokens = new ArrayList(0);
- sb = new StringBuffer(srcsb.toString());
while ((startIndex = sb.indexOf("/*", startIndex)) >= 0) {
preserve = sb.length() > startIndex + 2 && sb.charAt(startIndex + 2) == '!';
endIndex = sb.indexOf("*/", startIndex + 2);
@@ -80,21 +93,6 @@ public void compress(Writer out, int linebreakpos)
css = sb.toString();
- // preserve strings so their content doesn't get accidentally minified
- sb = new StringBuffer();
- p = Pattern.compile("(\"([^\\\\\"]|\\\\.|\\\\)*\")|(\'([^\\\\\']|\\\\.|\\\\)*\')");
- m = p.matcher(css);
- while (m.find()) {
- token = m.group();
- char quote = token.charAt(0);
- token = token.substring(1, token.length() - 1);
- preservedTokens.add(token);
- String preserver = quote + "___YUICSSMIN_PRESERVED_TOKEN_" + (preservedTokens.size() - 1) + "___" + quote;
- m.appendReplacement(sb, preserver);
- }
- m.appendTail(sb);
- css = sb.toString();
-
// Normalize all whitespace strings to single spaces. Easier to work with that way.
css = css.replaceAll("\\s+", " ");
View
1  tests/preserve-strings.css
@@ -3,4 +3,5 @@
content: "\"keep \" me";
something: '\\\' . . ';
else: 'empty{}';
+ content: "/* test */"; /* <---- this is not a comment, should be be kept */
}
View
2  tests/preserve-strings.css.min
@@ -1 +1 @@
-.sele{content:"\"keep \" me";something:'\\\' . . ';else:'empty{}'}
+.sele{content:"\"keep \" me";something:'\\\' . . ';else:'empty{}';content:"/* test */"}
Please sign in to comment.
Something went wrong with that request. Please try again.