diff --git a/.gitignore b/.gitignore index e3ebe20..ca2c1a9 100644 --- a/.gitignore +++ b/.gitignore @@ -6,5 +6,5 @@ /.idea/ /composer.lock -/vendor/ +/vendor /.php_cs.cache diff --git a/HISTORY.md b/HISTORY.md index e693074..641efe0 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -5,6 +5,7 @@ * Removes DooDigestAuth * Removes Minify_Loader (uses Composer) * Removes Minify_Logger (uses Monolog) +* Removes `$min_libPath` option * The Minify, source, and controller components have changed APIs * Better CSS minification via Túbal Martín's CSSMin * Add config option for simply concatenating files @@ -12,6 +13,14 @@ * Missing spec no longer redirects, instead links to docs * Minify::VERSION is an int that tracks the major version number +## Version 2.3.0 (2016-03-11) +* Adds `$min_concatOnly` option to just concatenate files +* Deprecates use of Minify_Loader +* Deprecates use of Minify_Logger +* Deprecates use of JSMinPlus +* Deprecates use of FirePHP +* Deprecates use of DooDigestAuth + ## Version 2.2.1 (2014-10-30) * Builder styled with Bootstrap (thanks to help from acidvertigo) * Update CSSmin to v.2.4.8 diff --git a/config.php b/config.php index 530a196..1c1cd4f 100644 --- a/config.php +++ b/config.php @@ -56,6 +56,7 @@ $min_allowDebugFlag = false; //$min_cachePath = '/tmp'; //$min_cachePath = preg_replace('/^\\d+;/', '', session_save_path()); + /** * To use APC/Memcache/ZendPlatform for cache storage, require the class and * set $min_cachePath to an instance. Example below: diff --git a/lib/Minify/CSS/UriRewriter.php b/lib/Minify/CSS/UriRewriter.php index ad6ae0e..93bf321 100644 --- a/lib/Minify/CSS/UriRewriter.php +++ b/lib/Minify/CSS/UriRewriter.php @@ -67,12 +67,16 @@ class Minify_CSS_UriRewriter { $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; } @@ -91,12 +95,16 @@ class Minify_CSS_UriRewriter { $css = self::_trimUrls($css); + $css = self::_owlifySvgPaths($css); + // append $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); + self::$_prependPath = null; return $css; @@ -308,4 +316,29 @@ 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/lib/Minify/Source/Factory.php b/lib/Minify/Source/Factory.php index 0c2535b..476e798 100644 --- a/lib/Minify/Source/Factory.php +++ b/lib/Minify/Source/Factory.php @@ -157,16 +157,19 @@ class Minify_Source_Factory { } if ($this->options['checkAllowDirs']) { + $allowDirs = (array)$this->options['allowDirs']; $inAllowedDir = false; - foreach ((array)$this->options['allowDirs'] as $allowDir) { + foreach ($allowDirs as $allowDir) { if (strpos($this->getNormalizedPath($spec['filepath']), $this->getNormalizedPath($allowDir)) === 0) { $inAllowedDir = true; } } if (!$inAllowedDir) { - throw new Minify_Source_FactoryException("File '{$spec['filepath']}' is outside \$allowDirs." - . " If the path is resolved via an alias/symlink, look into the \$min_symlinks option."); + $allowDirsStr = implode(';', $allowDirs); + throw new Minify_Source_FactoryException("File '{$spec['filepath']}' is outside \$allowDirs " + . "($allowDirsStr). If the path is resolved via an alias/symlink, look into the " + . "\$min_symlinks option."); } } diff --git a/tests/_test_files/css_uriRewriter/exp.css b/tests/_test_files/css_uriRewriter/exp.css index 22c109f..3296c26 100644 --- a/tests/_test_files/css_uriRewriter/exp.css +++ b/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/tests/_test_files/css_uriRewriter/exp_prepend.css b/tests/_test_files/css_uriRewriter/exp_prepend.css index ce31df1..bc09c44 100644 --- a/tests/_test_files/css_uriRewriter/exp_prepend.css +++ b/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/tests/_test_files/css_uriRewriter/exp_prepend2.css b/tests/_test_files/css_uriRewriter/exp_prepend2.css index 087d94d..c8f7c61 100644 --- a/tests/_test_files/css_uriRewriter/exp_prepend2.css +++ b/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/tests/_test_files/css_uriRewriter/in.css b/tests/_test_files/css_uriRewriter/in.css index 3bdce36..0200450 100644 --- a/tests/_test_files/css_uriRewriter/in.css +++ b/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 */