From ba5655f7e6cc54f22fd3fec4a115437c9b03afb2 Mon Sep 17 00:00:00 2001 From: Kavit Trivedi Date: Mon, 10 Nov 2025 15:03:18 +0530 Subject: [PATCH] - Fix CSS Minifier to Preserve Spaces in Mathematical Expressions --- cssmin/Minifier.php | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) 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