CSSMin: Don't do file_exists on random data in getLocalFileReferences()
authorBartosz Dziewoński <matma.rex@gmail.com>
Thu, 27 Feb 2014 13:16:39 +0000 (14:16 +0100)
committerBartosz Dziewoński <matma.rex@gmail.com>
Mon, 10 Mar 2014 19:55:02 +0000 (20:55 +0100)
If it's a URL, it obviously can't be a local file; check that first to
avoid PHP warnings about malformed paths.

Bug: 60960
Change-Id: Id784c089c3de8af79af7524ef5ab5cc2f7b8af9e

RELEASE-NOTES-1.23
includes/libs/CSSMin.php

index bdb75e8..344c967 100644 (file)
@@ -158,6 +158,8 @@ production.
 * (bug 26811) When a DBUnexpectedError occurs, DB server hostnames are now
   hidden unless $wgShowExceptionDetails is true, and $wgShowDBErrorBacktrace
   no longer applies in such cases.
+* (bug 60960) Avoid doing file_exist() checks on data: URIs, as they cause
+  warnings to be printed on Windows due to large path length.
 
 === Web API changes in 1.23 ===
 * (bug 54884) action=parse&prop=categories now indicates hidden and missing
index e490e4f..e3a3e2c 100644 (file)
@@ -79,11 +79,20 @@ class CSSMin {
                $rFlags = PREG_OFFSET_CAPTURE | PREG_SET_ORDER;
                if ( preg_match_all( '/' . self::URL_REGEX . '/', $source, $matches, $rFlags ) ) {
                        foreach ( $matches as $match ) {
-                               $file = $path . $match['file'][0];
-                               // Only proceed if we can access the file
+                               $url = $match['file'][0];
+
+                               // Skip fully-qualified and protocol-relative URLs and data URIs
+                               if ( substr( $url, 0, 2 ) === '//' || parse_url( $url, PHP_URL_SCHEME ) ) {
+                                       break;
+                               }
+
+                               $file = $path . $url;
+                               // Skip non-existent files
                                if ( file_exists( $file ) ) {
-                                       $files[] = $file;
+                                       break;
                                }
+
+                               $files[] = $file;
                        }
                }
                return $files;
@@ -246,8 +255,7 @@ class CSSMin {
                $url = $file . $query;
 
                // Skip fully-qualified and protocol-relative URLs and data URIs
-               $urlScheme = substr( $url, 0, 2 ) === '//' || parse_url( $url, PHP_URL_SCHEME );
-               if ( $urlScheme ) {
+               if ( substr( $url, 0, 2 ) === '//' || parse_url( $url, PHP_URL_SCHEME ) ) {
                        return $url;
                }