Bug in CSSMin.php
-
I’ve stumbled upon a longstanding bug in CSSMin.php regarding @keyframe rules, resulting in invalid CSS code after minification. Here’s a patch:
--- CssMin.php.old 2014-07-31 23:54:20.988623978 +0200 +++ CssMin.php 2014-08-01 00:13:01.920546691 +0200 @@ -465,7 +465,7 @@ } elseif ($class === "CssAtKeyframesStartToken") { - $r[] = $indent . "@keyframes \"" . $token->Name . "\""; + $r[] = $indent . "@keyframes " . $token->Name . ""; $r[] = $this->indent . $indent . "{"; $level++; } @@ -1840,7 +1840,7 @@ } elseif ($class === "CssAtKeyframesStartToken") { - $r[] = $indent . "@keyframes \"" . $token->Name . "\" {"; + $r[] = $indent . "@keyframes " . $token->Name . " {"; $level++; } elseif ($class === "CssAtMediaStartToken") @@ -3325,7 +3325,7 @@ public function apply(array &$tokens) { $r = 0; - $transformations = array("-moz-keyframes", "-webkit-keyframes"); + $transformations = array("-moz-keyframes", "-webkit-keyframes", "-o-keyframes", "-ms-keyframes"); for ($i = 0, $l = count($tokens); $i < $l; $i++) { if (get_class($tokens[$i]) === "CssAtKeyframesStartToken") @@ -4435,7 +4435,7 @@ */ public function __toString() { - return "@" . $this->AtRuleName . " \"" . $this->Name . "\"{"; + return "@" . $this->AtRuleName . " " . $this->Name . "{"; } } @@ -4574,6 +4574,23 @@ $this->parser->clearBuffer(); return $index + 15; } + // Start of @keyframes at-rule block (@-ms-keyframes) + else if ($char === "@" && $state === "T_DOCUMENT" && strtolower(substr($this->parser->getSource(), $index, 14)) === "@-ms-keyframes") + { + $this->atRuleName = "-ms-keyframes"; + $this->parser->pushState("T_AT_KEYFRAMES::NAME"); + $this->parser->clearBuffer(); + return $index + 14; + } + // Start of @keyframes at-rule block (@-o-keyframes) + else if ($char === "@" && $state === "T_DOCUMENT" && strtolower(substr($this->parser->getSource(), $index, 13)) === "@-o-keyframes") + { + $this->atRuleName = "-o-keyframes"; + $this->parser->pushState("T_AT_KEYFRAMES::NAME"); + $this->parser->clearBuffer(); + return $index + 13; + } + // Start of @keyframes at-rule block (@-webkit-keyframes) elseif ($char === "@" && $state === "T_DOCUMENT" && strtolower(substr($this->parser->getSource(), $index, 18)) === "@-webkit-keyframes") {
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
- The topic ‘Bug in CSSMin.php’ is closed to new replies.