mirror of
https://github.com/mrclay/minify.git
synced 2025-08-13 17:44:00 +02:00
Merge pull request #519 from mrclay/clip_path_517
No longer alters inline SVG id URLs
This commit is contained in:
@@ -66,16 +66,20 @@ class Minify_CSS_UriRewriter {
|
||||
self::$debugText .= "\n";
|
||||
|
||||
$css = self::_trimUrls($css);
|
||||
|
||||
|
||||
$css = self::_owlifySvgPaths($css);
|
||||
|
||||
// rewrite
|
||||
$css = preg_replace_callback('/@import\\s+([\'"])(.*?)[\'"]/'
|
||||
,array(self::$className, '_processUriCB'), $css);
|
||||
$css = preg_replace_callback('/url\\(\\s*([\'"](.*?)[\'"]|[^\\)\\s]+)\\s*\\)/'
|
||||
,array(self::$className, '_processUriCB'), $css);
|
||||
|
||||
$css = self::_unOwlify($css);
|
||||
|
||||
return $css;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* In CSS content, prepend a path to relative URIs
|
||||
*
|
||||
@@ -90,6 +94,8 @@ class Minify_CSS_UriRewriter {
|
||||
self::$_prependPath = $path;
|
||||
|
||||
$css = self::_trimUrls($css);
|
||||
|
||||
$css = self::_owlifySvgPaths($css);
|
||||
|
||||
// append
|
||||
$css = preg_replace_callback('/@import\\s+([\'"])(.*?)[\'"]/'
|
||||
@@ -97,6 +103,8 @@ class Minify_CSS_UriRewriter {
|
||||
$css = preg_replace_callback('/url\\(\\s*([\'"](.*?)[\'"]|[^\\)\\s]+)\\s*\\)/'
|
||||
,array(self::$className, '_processUriCB'), $css);
|
||||
|
||||
$css = self::_unOwlify($css);
|
||||
|
||||
self::$_prependPath = null;
|
||||
return $css;
|
||||
}
|
||||
@@ -304,4 +312,30 @@ class Minify_CSS_UriRewriter {
|
||||
? "@import {$quoteChar}{$uri}{$quoteChar}"
|
||||
: "url({$quoteChar}{$uri}{$quoteChar})";
|
||||
}
|
||||
|
||||
/**
|
||||
* Mungs some inline SVG URL declarations so they won't be touched
|
||||
*
|
||||
* @link https://github.com/mrclay/minify/issues/517
|
||||
* @see _unOwlify
|
||||
*
|
||||
* @param string $css
|
||||
* @return string
|
||||
*/
|
||||
private static function _owlifySvgPaths($css) {
|
||||
return preg_replace('~\b((?:clip-path|mask|-webkit-mask)\s*\:\s*)url(\(\s*#\w+\s*\))~', '$1owl$2', $css);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Undo work of _owlify
|
||||
*
|
||||
* @see _owlifySvgPaths
|
||||
*
|
||||
* @param string $css
|
||||
* @return string
|
||||
*/
|
||||
private static function _unOwlify($css) {
|
||||
return preg_replace('~\b((?:clip-path|mask|-webkit-mask)\s*\:\s*)owl~', '$1url', $css);
|
||||
}
|
||||
}
|
||||
|
@@ -8,6 +8,10 @@
|
||||
@import url("/css/foo.css"); /* abs, should not alter */
|
||||
@import url(/css2/foo.css); /* abs, should not alter */
|
||||
@import url(foo:bar); /* scheme, should not alter */
|
||||
foo {clip-path:url(#c1)} /* inline clip path, should not alter */
|
||||
foo {clip-path:url(/_test_files/css_uriRewriter/foo.svg#c1)}
|
||||
foo {mask: url(#c1)} /* should not alter */
|
||||
foo {-webkit-mask: url(#c1)} /* should not alter */
|
||||
foo {background:url('/_test_files/css_uriRewriter/bar/foo.png')}
|
||||
foo {background:url('http://foo.com/css/foo.css');} /* scheme, should not alter */
|
||||
foo {background:url("//foo.com/css/foo.css");} /* protocol relative, should not alter */
|
||||
|
@@ -8,6 +8,10 @@
|
||||
@import url("/css/foo.css"); /* abs, should not alter */
|
||||
@import url(/css2/foo.css); /* abs, should not alter */
|
||||
@import url(foo:bar); /* scheme, should not alter */
|
||||
foo {clip-path:url(#c1)} /* inline clip path, should not alter */
|
||||
foo {clip-path:url(http://cnd.com/A/B/foo.svg#c1)}
|
||||
foo {mask: url(#c1)} /* should not alter */
|
||||
foo {-webkit-mask: url(#c1)} /* should not alter */
|
||||
foo {background:url('http://cnd.com/A/B/bar/foo.png')}
|
||||
foo {background:url('http://foo.com/css/foo.css');} /* scheme, should not alter */
|
||||
foo {background:url("//foo.com/css/foo.css");} /* protocol relative, should not alter */
|
||||
|
@@ -8,6 +8,10 @@
|
||||
@import url("/css/foo.css"); /* abs, should not alter */
|
||||
@import url(/css2/foo.css); /* abs, should not alter */
|
||||
@import url(foo:bar); /* scheme, should not alter */
|
||||
foo {clip-path:url(#c1)} /* inline clip path, should not alter */
|
||||
foo {clip-path:url(//cnd.com/A/B/foo.svg#c1)}
|
||||
foo {mask: url(#c1)} /* should not alter */
|
||||
foo {-webkit-mask: url(#c1)} /* should not alter */
|
||||
foo {background:url('//cnd.com/A/B/bar/foo.png')}
|
||||
foo {background:url('http://foo.com/css/foo.css');} /* scheme, should not alter */
|
||||
foo {background:url("//foo.com/css/foo.css");} /* protocol relative, should not alter */
|
||||
|
@@ -8,6 +8,10 @@
|
||||
@import url("/css/foo.css"); /* abs, should not alter */
|
||||
@import url(/css2/foo.css); /* abs, should not alter */
|
||||
@import url(foo:bar); /* scheme, should not alter */
|
||||
foo {clip-path:url(#c1)} /* inline clip path, should not alter */
|
||||
foo {clip-path:url(foo.svg#c1)}
|
||||
foo {mask: url( #c1 )} /* should not alter */
|
||||
foo {-webkit-mask: url( #c1 )} /* should not alter */
|
||||
foo {background:url('bar/foo.png')}
|
||||
foo {background:url('http://foo.com/css/foo.css');} /* scheme, should not alter */
|
||||
foo {background:url("//foo.com/css/foo.css");} /* protocol relative, should not alter */
|
||||
|
Reference in New Issue
Block a user