changcheng / wro4j

Automatically exported from code.google.com/p/wro4j
0 stars 0 forks source link

CSSMin bug on Properties containing colon ":" #378

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Use the CssMinProcessor
2. In CSS define a filter of the form:
.myclass {
  filter: progid:ImageTransform.Microsoft.gradient(startColorstr='#ffffff', endColorstr='#000000');
}
3. Execute wro4j 

What is the expected output? What do you see instead?
Expected result in CSS
.myclass {
 filter: progid:ImageTransform.Microsoft.gradient(startColorstr='#ffffff', endColorstr='#000000');
}
Instead I get:
.myclass {
  filter: progid;
}

What version of the product are you using? On what operating system?
1.4.3

Please provide any additional information below.

In the Property class in CSSMin the 'property' String is split at colons ":". 
This does not work when the property value itself contains a colon as it is the 
case with IE gradients:
filter: progid:ImageTransform.Microsoft.gradient();

As a fix use String.split(String regex, int limit) and limit the resulting 
String array to 2 elements, thus containing the property and the complete value 
including potential colons.
See 
http://docs.oracle.com/javase/6/docs/api/java/lang/String.html#split(java.lang.S
tring,%20int)

A possible fix looks like this:
  public Property(final String property) throws Exception {
    try {
      // Parse the property.
      // final String[] parts = property.split(":"); // Split "color: red" to ["color", " red"]
      /* fix for IE gradient problem: */
      final String[] parts = property.split(":", 2); // Split "color: red" to ["color", " red"]
      if (parts.length < 2) {
        throw new Exception("Warning: Incomplete property: " + property);
      }
      this.property = parts[0].trim().toLowerCase();

      values = parseValues(parts[1].trim().replaceAll(", ", ","));

    } catch (final PatternSyntaxException e) {
      // Invalid regular expression used.
    }
  }

Original issue reported on code.google.com by peterc...@googlemail.com on 17 Feb 2012 at 5:05

GoogleCodeExporter commented 9 years ago
The CssMin is a legacy code which was imported to main project distribution. 
I'll update the implementation according to your suggestion. 

Thanks!

Original comment by alex.obj...@gmail.com on 17 Feb 2012 at 5:12

GoogleCodeExporter commented 9 years ago

Original comment by alex.obj...@gmail.com on 17 Feb 2012 at 5:13

GoogleCodeExporter commented 9 years ago

Original comment by alex.obj...@gmail.com on 17 Feb 2012 at 7:38