Skip to content
This repository
Browse code

Merged 2.4.7

  • Loading branch information...
commit d908eec9fb9c7865e5fe70e38a7de7e27c0fc521 2 parents 2be7440 + 91c5ea5
authored September 27, 2011
3  build.xml
@@ -20,7 +20,8 @@
20 20
                includes="**/*.java"
21 21
                deprecation="off"
22 22
                debug="on"
23  
-               source="1.6">
  23
+	       target="1.5"
  24
+               source="1.5">
24 25
             <classpath>
25 26
                 <pathelement location="${lib.dir}/jargs-1.0.jar"/>
26 27
                 <pathelement location="${lib.dir}/rhino-1.7R2.jar"/>
33  ports/js/cssmin.js
@@ -107,7 +107,7 @@ YAHOO.compressor._extractDataUrls = function (css, preservedTokens) {
107 107
  *
108 108
  * DOES NOT compress IE filters, which have hex color values (which would break things). 
109 109
  * e.g. filter: chroma(color="#FFFFFF");
110  
- * 
  110
+ *
111 111
  * DOES NOT compress invalid hex values.
112 112
  * e.g. background-color: #aabbccdd
113 113
  *
@@ -119,28 +119,35 @@ YAHOO.compressor._extractDataUrls = function (css, preservedTokens) {
119 119
 YAHOO.compressor._compressHexColors = function(css) {
120 120
 
121 121
     // Look for hex colors inside { ... } (to avoid IDs) and which don't have a =, or a " in front of them (to avoid filters)
122  
-    var pattern = /([^"'=\s])(\s*)#([0-9a-f])([0-9a-f])([0-9a-f])([0-9a-f])([0-9a-f])([0-9a-f])(\}|[^0-9a-f{][^{]*?\})/gi,
  122
+    var pattern = /(\=\s*?["']?)?#([0-9a-f])([0-9a-f])([0-9a-f])([0-9a-f])([0-9a-f])([0-9a-f])(\}|[^0-9a-f{][^{]*?\})/gi,
123 123
         m,
124 124
         index = 0,
  125
+        isFilter,
125 126
         sb = [];
126 127
 
127 128
     while ((m = pattern.exec(css)) !== null) {
128 129
 
129  
-        if (m[3].toLowerCase() == m[4].toLowerCase() &&
130  
-            m[5].toLowerCase() == m[6].toLowerCase() &&
131  
-            m[7].toLowerCase() == m[8].toLowerCase()) {
  130
+        sb.push(css.substring(index, m.index));
132 131
 
133  
-            // Enough searching, start moving stuff over to the buffer
134  
-            sb.push(css.substring(index, m.index));
135  
-            sb.push((m[1] + m[2] + "#" + m[3] + m[5] + m[7]).toLowerCase());
  132
+        isFilter = m[1];
136 133
 
137  
-            index = pattern.lastIndex = pattern.lastIndex - m[9].length;
  134
+        if (isFilter) {
  135
+            // Restore, maintain case, otherwise filter will break
  136
+            sb.push(m[1] + "#" + (m[2] + m[3] + m[4] + m[5] + m[6] + m[7]));
138 137
         } else {
139  
-            sb.push(css.substring(index, m.index));
140  
-            sb.push((m[1] + m[2] + "#" + m[3] + m[4] + m[5] + m[6] + m[7] + m[8]).toLowerCase());
141  
-
142  
-            index = pattern.lastIndex = pattern.lastIndex - m[9].length;
  138
+            if (m[2].toLowerCase() == m[3].toLowerCase() &&
  139
+                m[4].toLowerCase() == m[5].toLowerCase() &&
  140
+                m[6].toLowerCase() == m[7].toLowerCase()) {
  141
+
  142
+                // Compress.
  143
+                sb.push("#" + (m[3] + m[5] + m[7]).toLowerCase());
  144
+            } else {
  145
+                // Non compressible color, restore but lower case.
  146
+                sb.push("#" + (m[2] + m[3] + m[4] + m[5] + m[6] + m[7]).toLowerCase());
  147
+            }
143 148
         }
  149
+
  150
+        index = pattern.lastIndex = pattern.lastIndex - m[8].length;
144 151
     }
145 152
 
146 153
     sb.push(css.substring(index));
40  src/com/yahoo/platform/yui/compressor/CssCompressor.java
@@ -292,25 +292,39 @@ public void compress(Writer out, int linebreakpos)
292 292
         // which makes the filter break in IE.
293 293
         // We also want to make sure we're only compressing #AABBCC patterns inside { }, not id selectors ( #FAABAC {} )
294 294
         // We also want to avoid compressing invalid values (e.g. #AABBCCD to #ABCD)
295  
-        p = Pattern.compile("([^\"'=\\s])" + "(\\s*)" + "#([0-9a-fA-F])([0-9a-fA-F])([0-9a-fA-F])([0-9a-fA-F])([0-9a-fA-F])([0-9a-fA-F])" + "(:?\\}|[^0-9a-fA-F{][^{]*?\\})");
  295
+        p = Pattern.compile("(\\=\\s*?[\"']?)?" + "#([0-9a-fA-F])([0-9a-fA-F])([0-9a-fA-F])([0-9a-fA-F])([0-9a-fA-F])([0-9a-fA-F])" + "(:?\\}|[^0-9a-fA-F{][^{]*?\\})");
  296
+
296 297
         m = p.matcher(css);
297 298
         sb = new StringBuffer();
298 299
         int index = 0;
  300
+
299 301
         while (m.find(index)) {
300  
-        	if (m.group(3).equalsIgnoreCase(m.group(4)) &&
301  
-                    m.group(5).equalsIgnoreCase(m.group(6)) &&
302  
-                    m.group(7).equalsIgnoreCase(m.group(8))) {
303  
-                // #AABBCC pattern
304  
-                sb.append(css.substring(index, m.start(1)));
305  
-                sb.append((m.group(1) + m.group(2) + "#" + m.group(3) + m.group(5) + m.group(7)).toLowerCase());
306  
-                index = m.end(8);
307  
-            } else {
308  
-                // Any other color.
309  
-                sb.append(css.substring(index, m.start(1)));
310  
-                sb.append((m.group(1) + m.group(2) + "#" + m.group(3) + m.group(4) + m.group(5) + m.group(6) + m.group(7) + m.group(8)).toLowerCase());
311  
-                index = m.end(8);
  302
+
  303
+        	sb.append(css.substring(index, m.start()));
  304
+
  305
+        	boolean isFilter = (m.group(1) != null && !"".equals(m.group(1))); 
  306
+
  307
+        	if (isFilter) {
  308
+        		// Restore, as is. Compression will break filters
  309
+        		sb.append(m.group(1) + "#" + m.group(2) + m.group(3) + m.group(4) + m.group(5) + m.group(6) + m.group(7));
  310
+        	} else {
  311
+        		if( m.group(2).equalsIgnoreCase(m.group(3)) &&
  312
+                    m.group(4).equalsIgnoreCase(m.group(5)) &&
  313
+                    m.group(6).equalsIgnoreCase(m.group(7))) {
  314
+
  315
+	        		// #AABBCC pattern
  316
+	                sb.append("#" + (m.group(3) + m.group(5) + m.group(7)).toLowerCase());
  317
+
  318
+        		} else {
  319
+
  320
+        			// Non-compressible color, restore, but lower case.
  321
+        			sb.append("#" + (m.group(2) + m.group(3) + m.group(4) + m.group(5) + m.group(6) + m.group(7)).toLowerCase());
  322
+        		}
312 323
             }
  324
+
  325
+        	index = m.end(7);
313 326
         }
  327
+
314 328
         sb.append(css.substring(index));
315 329
         css = sb.toString();
316 330
 
8  tests/color-simple.css
... ...
@@ -0,0 +1,8 @@
  1
+.foo, #AABBCC {
  2
+  background-color:#aabbcc;
  3
+  border-color:#Ee66aA #ABCDEF #FeAb2C;
  4
+  filter:chroma(color = #FFFFFF );
  5
+  filter:chroma(color="#AABBCC");
  6
+  filter:chroma(color='#BBDDEE');
  7
+  color:#112233
  8
+}
1  tests/color-simple.css.min
... ...
@@ -0,0 +1 @@
  1
+.foo,#AABBCC{background-color:#abc;border-color:#e6a #abcdef #feab2c;filter:chroma(color = #FFFFFF);filter:chroma(color="#AABBCC");filter:chroma(color='#BBDDEE');color:#123}
10  tests/color.css
... ...
@@ -1,7 +1,7 @@
1 1
 .color {
2 2
   me: rgb(123, 123, 123);
3 3
   impressed: #FfEedD;
4  
-  again: #456789;
  4
+  again: #ABCDEF;
5 5
   andagain:#aa66cc;
6 6
   background-color:#aa66ccc;
7 7
   filter: chroma(color="#FFFFFF");
@@ -12,24 +12,28 @@
12 12
 
13 13
 #AABBCC {
14 14
   background-color:#ffee11;
15  
-  filter: chroma(color="#FFFFFF");
  15
+  filter: chroma(color = #FFFFFF );
16 16
   color:#441122;
  17
+  foo:#00fF11 #ABC #AABbCc #123344;
17 18
   border-color:#aa66ccC
18 19
 }
19 20
 
20 21
 .foo #AABBCC {
21 22
   background-color:#fFEe11;
22 23
   color:#441122;
23  
-  filter: chroma(color="#FFFFFF")
  24
+  border-color:#AbC;
  25
+  filter: chroma(color= #FFFFFF)
24 26
 }
25 27
 
26 28
 .bar, #AABBCC {
27 29
   background-color:#FFee11;
  30
+  border-color:#00fF11 #ABCDEF;
28 31
   color:#441122;
29 32
 }
30 33
 
31 34
 .foo, #AABBCC.foobar {
32 35
   background-color:#ffee11;
  36
+  border-color:#00fF11 #ABCDEF #AABbCc;
33 37
   color:#441122;
34 38
 }
35 39
 
4  tests/color.css.min
... ...
@@ -1,3 +1 @@
1  
-.color{me:#7b7b7b;impressed:#fed;again:#456789;andagain:#a6c;background-color:#aa66ccc;filter:chroma(color="#FFFFFF");background:none repeat scroll 0 0 #f00;alpha:rgba(1,2,3,4);color:#12a}#AABBCC{background-color:#fe1;filter:chroma(color="#FFFFFF");color:#412;border-color:#aa66ccC}.foo #AABBCC{background-color:#fe1;color:#412;filter:chroma(color="#FFFFFF")}.bar,#AABBCC{background-color:#fe1;color:#412}.foo,#AABBCC.foobar{background-color:#fe1;color:#412}@media screen{.bar,#AABBCC{background-color:#fe1;color:#412}}
2  
-
3  
-
  1
+.color{me:#7b7b7b;impressed:#fed;again:#abcdef;andagain:#a6c;background-color:#aa66ccc;filter:chroma(color="#FFFFFF");background:none repeat scroll 0 0 #f00;alpha:rgba(1,2,3,4);color:#12a}#AABBCC{background-color:#fe1;filter:chroma(color = #FFFFFF);color:#412;foo:#0f1 #ABC #abc #123344;border-color:#aa66ccC}.foo #AABBCC{background-color:#fe1;color:#412;border-color:#AbC;filter:chroma(color= #FFFFFF)}.bar,#AABBCC{background-color:#fe1;border-color:#0f1 #abcdef;color:#412}.foo,#AABBCC.foobar{background-color:#fe1;border-color:#0f1 #abcdef #abc;color:#412}@media screen{.bar,#AABBCC{background-color:#fe1;color:#412}}

0 notes on commit d908eec

Please sign in to comment.
Something went wrong with that request. Please try again.