From ae839a0facaaf7d0b8e8af64a8cd14b09bfb8b82 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Bartosz=20Dziewo=C5=84ski?= Date: Thu, 27 Feb 2014 14:08:48 +0100 Subject: [PATCH] CSSMin: Clean up the logic in getLocalFileReferences() MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit The function used to check if the $path parameter is null on every inner loop iteration, only to effectively return an empty array if it was. Rephrased the code to say exactly that. (Not sure what the behavior is good for, though…) Change-Id: I716bfde581d3ed4c02f0d9f544beb9d0a1906261 --- includes/libs/CSSMin.php | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/includes/libs/CSSMin.php b/includes/libs/CSSMin.php index 3b7968457d..e490e4f41d 100644 --- a/includes/libs/CSSMin.php +++ b/includes/libs/CSSMin.php @@ -61,21 +61,27 @@ class CSSMin { /** * Gets a list of local file paths which are referenced in a CSS style sheet * + * This function will always return an empty array if the second parameter is not given or null + * for backwards-compatibility. + * * @param string $source CSS data to remap * @param string $path File path where the source was read from (optional) * @return array List of local file references */ public static function getLocalFileReferences( $source, $path = null ) { + if ( $path === null ) { + return array(); + } + + $path = rtrim( $path, '/' ) . '/'; $files = array(); + $rFlags = PREG_OFFSET_CAPTURE | PREG_SET_ORDER; if ( preg_match_all( '/' . self::URL_REGEX . '/', $source, $matches, $rFlags ) ) { foreach ( $matches as $match ) { - $file = ( isset( $path ) - ? rtrim( $path, '/' ) . '/' - : '' ) . "{$match['file'][0]}"; - + $file = $path . $match['file'][0]; // Only proceed if we can access the file - if ( !is_null( $path ) && file_exists( $file ) ) { + if ( file_exists( $file ) ) { $files[] = $file; } } -- 2.20.1