From bd9a450694cda1b54c43a1784adabe36ad522d89 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Elan=20Ruusam=C3=A4e?= Date: Thu, 25 Sep 2014 14:40:53 +0300 Subject: [PATCH] update cssmin to v2.4.8-4. fixes #123 --- composer.json | 10 ++++++++-- min/lib/CSSmin.php | 16 +++++++++------- 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/composer.json b/composer.json index 701894f..bb6b870 100644 --- a/composer.json +++ b/composer.json @@ -16,11 +16,17 @@ "issues": "http://code.google.com/p/minify/issues/list", "wiki": "http://code.google.com/p/minify/w/list" }, + "autoload": { + "classmap": ["min/lib/"] + }, "require": { "php": ">=5.2.1", "ext-pcre": "*" }, - "autoload": { - "classmap": ["min/lib/"] + "require-dev": { + "tubalmartin/cssmin": "~2.4.8" + }, + "suggest": { + "tubalmartin/cssmin": "Support minify with CSSMin (YUI PHP port)" } } diff --git a/min/lib/CSSmin.php b/min/lib/CSSmin.php index e85f23e..fab0102 100644 --- a/min/lib/CSSmin.php +++ b/min/lib/CSSmin.php @@ -1,7 +1,7 @@ \+\(\)\]\~\=,])/', '$1', $css); @@ -336,11 +336,13 @@ class CSSmin // to avoid issues on Symbian S60 3.x browsers. $css = preg_replace('/(\*[a-z0-9\-]+\s*\:[^;\}]+)(\})/', '$1;$2', $css); - // Replace 0 length units 0(px,em,%) with 0. - $css = preg_replace('/(^|[^0-9])(?:0?\.)?0(?:em|ex|ch|rem|vw|vh|vm|vmin|cm|mm|in|px|pt|pc|%|deg|g?rad|m?s|k?hz)/iS', '${1}0', $css); + // Replace 0 and 0 values with 0. + // data type: https://developer.mozilla.org/en-US/docs/Web/CSS/length + // data type: https://developer.mozilla.org/en-US/docs/Web/CSS/percentage + $css = preg_replace('/([^\\\\]\:|\s)0(?:em|ex|ch|rem|vw|vh|vm|vmin|cm|mm|in|px|pt|pc|%)/iS', '${1}0', $css); // 0% step in a keyframe? restore the % unit - $css = preg_replace_callback('/(@[a-z\-]*?keyframes[^\{]*?\{)(.*?\}\s*\})/iS', array($this, 'replace_keyframe_zero'), $css); + $css = preg_replace_callback('/(@[a-z\-]*?keyframes[^\{]+\{)(.*?)(\}\})/iS', array($this, 'replace_keyframe_zero'), $css); // Replace 0 0; or 0 0 0; or 0 0 0 0; with 0. $css = preg_replace('/\:0(?: 0){1,3}(;|\}| \!)/', ':0$1', $css); @@ -596,7 +598,7 @@ class CSSmin private function replace_keyframe_zero($matches) { - return $matches[1] . preg_replace('/0\s*,/', '0%,', preg_replace('/\s*0\s*\{/', '0%{', $matches[2])); + return $matches[1] . preg_replace('/0(\{|,[^\)\{]+\{)/', '0%$1', $matches[2]) . $matches[3]; } private function rgb_to_hex($matches)