Browse files

Merge pull request #231 from jochenberger/fix-zero-replacement

fix some minification errors related to zero value replacements
  • Loading branch information...
2 parents 80de90c + e687f07 commit b3de528f45966e418d6e3e2f6f8135db4d0be7f1 @tml tml committed on GitHub Jun 28, 2016
View
17 src/com/yahoo/platform/yui/compressor/CssCompressor.java
@@ -329,7 +329,22 @@ public void compress(Writer out, int linebreakpos)
css = css.replaceAll(";+}", "}");
// Replace 0(px,em,%) with 0.
- css = css.replaceAll("(?i)(^|[^.0-9])(?:0?\\.)?0(?:px|em|%|in|cm|mm|pc|pt|ex|deg|g?rad|m?s|k?hz)", "$10");
+ String oldCss;
+ p = Pattern.compile("(?i)(^|: ?)((?:[0-9a-z-.]+ )*?)?(?:0?\\.)?0(?:px|em|%|in|cm|mm|pc|pt|ex|deg|g?rad|m?s|k?hz)");
+ do {
+ oldCss = css;
+ m = p.matcher(css);
+ css = m.replaceAll("$1$20");
+ } while (!(css.equals(oldCss)));
+
+ // Replace 0(px,em,%) with 0 inside groups (e.g. -MOZ-RADIAL-GRADIENT(CENTER 45DEG, CIRCLE CLOSEST-SIDE, ORANGE 0%, RED 100%))
+ p = Pattern.compile("(?i)\\( ?((?:[0-9a-z-.]+[ ,])*)?(?:0?\\.)?0(?:px|em|%|in|cm|mm|pc|pt|ex|deg|g?rad|m?s|k?hz)");
+ do {
+ oldCss = css;
+ m = p.matcher(css);
+ css = m.replaceAll("($10");
+ } while (!(css.equals(oldCss)));
+
// Replace x.0(px,em,%) with x(px,em,%).
css = css.replaceAll("([0-9])\\.0(px|em|%|in|cm|mm|pc|pt|ex|deg|g?rad|m?s|k?hz| |;)", "$1$2");
View
0 tests/issue151.css.FAIL → tests/issue151.css
File renamed without changes.
View
0 tests/issue221.css.FAIL → tests/issue221.css
File renamed without changes.
View
0 tests/issue222.css.FAIL → tests/issue222.css
File renamed without changes.

0 comments on commit b3de528

Please sign in to comment.