mirror of
https://github.com/getgrav/grav.git
synced 2025-02-20 19:56:53 +01:00
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.
This commit is contained in:
parent
504f3df857
commit
97ffb87d69
|
|
@ -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]);
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user