Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions cssmin/Minifier.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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
Expand Down
Loading