diff --git a/cssmin/Minifier.php b/cssmin/Minifier.php index ccbf6e5..a09e2bc 100644 --- a/cssmin/Minifier.php +++ b/cssmin/Minifier.php @@ -326,6 +326,13 @@ private function minify($css) $css ); + // Process mathematical expressions so their operators don't get accidentally minified + $css = preg_replace_callback( + '/\b\d*\.?\d+[a-z%]*\s*[\+\-\*\/]\s*\d*\.?\d+[a-z%]*\b/Si', + array($this, 'processMathematicalExpressionCallback'), + $css + ); + // Normalize all whitespace strings to single spaces. Easier to work with that way. $css = preg_replace('/\s+/S', ' ', $css); @@ -454,6 +461,16 @@ private function processStringsCallback($matches) return $quote . $this->registerPreservedToken($match) . $quote; } + /** + * Preserves mathematical expressions found + * @param array $matches + * @return string + */ + private function processMathematicalExpressionCallback($matches) + { + return $this->registerPreservedToken($matches[0]); + } + /** * Preserves or removes comments found. * @param string $css