MDL-29864: Port a patch from upstream minify project to handle spaces in font-family...
authorAndrew Robert Nicols <andrew.nicols@luns.net.uk>
Mon, 24 Oct 2011 08:29:52 +0000 (09:29 +0100)
committerAndrew Robert Nicols <andrew.nicols@luns.net.uk>
Mon, 24 Oct 2011 09:48:05 +0000 (10:48 +0100)
No upstream release of minify with this patch included is available yet, so
I've ported just the relevant part of the fixing commit.

lib/minify/lib/Minify/CSS/Compressor.php
lib/minify/readme_moodle.txt

index d483b2f..dad700a 100644 (file)
@@ -236,15 +236,16 @@ class Minify_CSS_Compressor {
      */
     protected function _fontFamilyCB($m)
     {
-        $m[1] = preg_replace('/
-                \\s*
-                (
-                    "[^"]+"      # 1 = family in double qutoes
-                    |\'[^\']+\'  # or 1 = family in single quotes
-                    |[\\w\\-]+   # or 1 = unquoted family
-                )
-                \\s*
-            /x', '$1', $m[1]);
-        return 'font-family:' . $m[1] . $m[2];
+        // Issue 210: must not eliminate WS between words in unquoted families
+        $pieces = preg_split('/(\'[^\']+\'|"[^"]+")/', $m[1], null, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY);
+        $out = 'font-family:';
+        while (null !== ($piece = array_shift($pieces))) {
+            if ($piece[0] !== '"' && $piece[0] !== "'") {
+                $piece = preg_replace('/\\s+/', ' ', $piece);
+                $piece = preg_replace('/\\s?,\\s?/', ',', $piece);
+            }
+            $out .= $piece;
+        }
+        return $out . $m[2];
     }
 }
index bd798f2..f7be3f4 100644 (file)
@@ -15,3 +15,5 @@ Changes:
  * Removed .htaccess - Not needed
  * Changed config.php - Changed settings to Moodle specific settings incase this
    ever gets accidentally used.
+ * Updated lib/Minify/CSS/Compressor.php - Applied an upstream fix for MDL-29864
+   to allow usage of unquoted font-familes with spaces in CSS.