From 12b9096b23587720f015fa61b8a65de2cf1ba656 Mon Sep 17 00:00:00 2001 From: Steve Clay Date: Wed, 18 Jan 2017 18:48:15 -0500 Subject: [PATCH] URI rewriter passes through empty URLs Fixes #561 --- lib/Minify/CSS/UriRewriter.php | 5 +++++ tests/_test_files/css_uriRewriter/exp.css | 2 ++ tests/_test_files/css_uriRewriter/exp_prepend.css | 2 ++ tests/_test_files/css_uriRewriter/exp_prepend2.css | 2 ++ tests/_test_files/css_uriRewriter/in.css | 2 ++ 5 files changed, 13 insertions(+) diff --git a/lib/Minify/CSS/UriRewriter.php b/lib/Minify/CSS/UriRewriter.php index 248875c..acd1a2c 100644 --- a/lib/Minify/CSS/UriRewriter.php +++ b/lib/Minify/CSS/UriRewriter.php @@ -294,6 +294,11 @@ class Minify_CSS_UriRewriter $uri = ($quoteChar === '') ? $m[1] : substr($m[1], 1, strlen($m[1]) - 2); } + + if ($uri === '') { + return $m[0]; + } + // if not root/scheme relative and not starts with scheme if (!preg_match('~^(/|[a-z]+\:)~', $uri)) { // URI is file-relative: rewrite depending on options diff --git a/tests/_test_files/css_uriRewriter/exp.css b/tests/_test_files/css_uriRewriter/exp.css index 3296c26..5ce7667 100644 --- a/tests/_test_files/css_uriRewriter/exp.css +++ b/tests/_test_files/css_uriRewriter/exp.css @@ -8,6 +8,7 @@ @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 */ +@import url(); /* empty, 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 */ @@ -17,5 +18,6 @@ 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 */ foo {background:url(foo:bar);} /* scheme, should not alter */ foo {background:url("/_test_files/css_uriRewriter/foo bar.jpg");} +foo {background:url("");} /* empty, should not alter */ @import url('/_test_files/css_uriRewriter/foo bar.css'); @import "/_test_files/css_uriRewriter/foo bar.css"; diff --git a/tests/_test_files/css_uriRewriter/exp_prepend.css b/tests/_test_files/css_uriRewriter/exp_prepend.css index bc09c44..a56103d 100644 --- a/tests/_test_files/css_uriRewriter/exp_prepend.css +++ b/tests/_test_files/css_uriRewriter/exp_prepend.css @@ -8,6 +8,7 @@ @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 */ +@import url(); /* empty, 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 */ @@ -17,5 +18,6 @@ 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 */ foo {background:url(foo:bar);} /* scheme, should not alter */ foo {background:url("http://cnd.com/A/B/foo bar.jpg");} +foo {background:url("");} /* empty, should not alter */ @import url('http://cnd.com/A/B/foo bar.css'); @import "http://cnd.com/A/B/foo bar.css"; diff --git a/tests/_test_files/css_uriRewriter/exp_prepend2.css b/tests/_test_files/css_uriRewriter/exp_prepend2.css index c8f7c61..f9398a5 100644 --- a/tests/_test_files/css_uriRewriter/exp_prepend2.css +++ b/tests/_test_files/css_uriRewriter/exp_prepend2.css @@ -8,6 +8,7 @@ @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 */ +@import url(); /* empty, 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 */ @@ -17,5 +18,6 @@ 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 */ foo {background:url(foo:bar);} /* scheme, should not alter */ foo {background:url("//cnd.com/A/B/foo bar.jpg");} +foo {background:url("");} /* empty, should not alter */ @import url('//cnd.com/A/B/foo bar.css'); @import "//cnd.com/A/B/foo bar.css"; diff --git a/tests/_test_files/css_uriRewriter/in.css b/tests/_test_files/css_uriRewriter/in.css index 0200450..e5c4858 100644 --- a/tests/_test_files/css_uriRewriter/in.css +++ b/tests/_test_files/css_uriRewriter/in.css @@ -8,6 +8,7 @@ @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 */ +@import url(); /* empty, 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 */ @@ -17,5 +18,6 @@ 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 */ foo {background:url(foo:bar);} /* scheme, should not alter */ foo {background:url("foo bar.jpg");} +foo {background:url("");} /* empty, should not alter */ @import url('foo bar.css'); @import "foo bar.css";