diff --git a/min/lib/Minify/CSS/UriRewriter.php b/min/lib/Minify/CSS/UriRewriter.php index 43cc254..e963fb8 100644 --- a/min/lib/Minify/CSS/UriRewriter.php +++ b/min/lib/Minify/CSS/UriRewriter.php @@ -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); + } } diff --git a/min_unit_tests/_test_files/css_uriRewriter/exp.css b/min_unit_tests/_test_files/css_uriRewriter/exp.css index 22c109f..3296c26 100644 --- a/min_unit_tests/_test_files/css_uriRewriter/exp.css +++ b/min_unit_tests/_test_files/css_uriRewriter/exp.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 */ diff --git a/min_unit_tests/_test_files/css_uriRewriter/exp_prepend.css b/min_unit_tests/_test_files/css_uriRewriter/exp_prepend.css index ce31df1..bc09c44 100644 --- a/min_unit_tests/_test_files/css_uriRewriter/exp_prepend.css +++ b/min_unit_tests/_test_files/css_uriRewriter/exp_prepend.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(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 */ diff --git a/min_unit_tests/_test_files/css_uriRewriter/exp_prepend2.css b/min_unit_tests/_test_files/css_uriRewriter/exp_prepend2.css index 087d94d..c8f7c61 100644 --- a/min_unit_tests/_test_files/css_uriRewriter/exp_prepend2.css +++ b/min_unit_tests/_test_files/css_uriRewriter/exp_prepend2.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(//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 */ diff --git a/min_unit_tests/_test_files/css_uriRewriter/in.css b/min_unit_tests/_test_files/css_uriRewriter/in.css index 3bdce36..0200450 100644 --- a/min_unit_tests/_test_files/css_uriRewriter/in.css +++ b/min_unit_tests/_test_files/css_uriRewriter/in.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(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 */