From 97ffb87d69e7a6b8e90ec6fd350223701c3e91f7 Mon Sep 17 00:00:00 2001 From: Philipp Kitzberger Date: Tue, 17 May 2016 01:57:08 +0200 Subject: [PATCH] Fix absolute URLs in pipelined CSS (#837) * Fix absolute URLs in pipelined CSS The way that absolute URLs get excluded during cssRewrite() doesn't cover all possible cases due to a incorrect CSS_URL_REGEX. * Improve CSS_URL_REGEX Performance improvement by using a back reference. Additionally this makes sure the same kind of quote (single, double, none) is being used. --- system/src/Grav/Common/Assets.php | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/system/src/Grav/Common/Assets.php b/system/src/Grav/Common/Assets.php index e08ec3425..64fd32077 100644 --- a/system/src/Grav/Common/Assets.php +++ b/system/src/Grav/Common/Assets.php @@ -34,7 +34,7 @@ class Assets const JS_REGEX = '/.\.js$/i'; /** @const Regex to match CSS urls */ - const CSS_URL_REGEX = '{url\([\'\"]?((?!http|//).*?)[\'\"]?\)}'; + const CSS_URL_REGEX = '{url\(([\'\"]?)(.*?)\1\)}'; /** @const Regex to match CSS sourcemap comments */ const CSS_SOURCEMAP_REGEX = '{\/\*# (.*) \*\/}'; @@ -1149,13 +1149,18 @@ class Assets // Then replace the old url with the new one $file = preg_replace_callback(self::CSS_URL_REGEX, function ($matches) use ($relative_path) { - $old_url = $matches[1]; + $old_url = $matches[2]; // ensure this is not a data url if (strpos($old_url, 'data:') === 0) { return $matches[0]; } + // ensure this is not a remote url + if ($this->isRemoteLink($old_url)) { + return $matches[0]; + } + $new_url = $this->base_url . ltrim(Utils::normalizePath($relative_path . '/' . $old_url), '/'); return str_replace($old_url, $new_url, $matches[0]);